This project has moved and is read-only. For the latest updates, please go here.

Inherited ExportAttribute and PartCreationPolicy

Jul 28, 2009 at 12:50 AM
Edited Jul 28, 2009 at 12:55 AM

Hi Again,

I'm trying to port to Preview 6, and retire our custom export providers by making our attributes inherit from ExportAttribute.

In the implementation of the ExportProvider, we were stuffing the ExportDefinition with the right PartCreationPolicy, but I'm now finding no way to set it other than individually on each class being marked with the custom attribute.

On the one hand the main drive to use the inherited attribute was to make MEF transparent to writers of extensions to our application (ie we don't want them to have to learn MEF for now, just know that they need to mark with the provided custom attributes). On the other hand, our desire to move away from the Export Provider was the potential for class bloat that implementing our own exportdefinition with its own handlers in the provider would otherwise generate.

What would be the recommended approach to achieve this?

To summarize, I'd like to be able to mark a class with a CustomAttribute and have all the information set in order to make it a Composable part.





Jul 31, 2009 at 7:30 PM

Thanks for the feedback.

One of the biggest problems with specifying CreationPolicy is that it applies to the Part (i.e. the entire type) and not simply the Export. A given part or type could have multiple Exports associated with it but can only have a single CreationPolicy. We have considered making PartCreationPolicy inheritable but in doing so there are a number of issues such as conflicting policies at different levels that we have to figure out the proper behavior for, so at this point we've decided not to support it.

Out of curiousity are people using CreationPolicy.Shared and NonShared for the same contract? Also you do realize that if the CreationPolicy isn't NonShared then the PartCreationPolicyAttribute doesn't need to be explicitly specified. By default it is CreationPolicy.Any in which case MEF will choose CreationPolicy.Shared as the creation policy.