I just discovered that the Managed Extensibility Framework will produce duplicate exports for parts that are exported with custom metadata. My scenario is pretty simple. I have created an Entity Framework DbContext subclass that is marked up with both [Export] and [DbContextMetadata] attributes. DbContextMetadataAttribute is my own custom metadata attribute.
1: [Export(typeof(IDbContext))]
2: [DbContextMetadata(ContextType = "Person")]
3: public class PersonContext : DbContext, IDbContext
4: {
The result is shown here:
I have verified that this is true by simply commenting out the custom metadata attribute. Interestingly, this behavior is not present when using the MEF ExportMetadataAttribute. I’m planning to dig into this a little more to see why it’s happening, but it certainly was unexpected.
Blogger Labels: Duplicate,Exports,Export,Metadata,Framework,custom,scenario,DbContext,DbContextMetadata,DbContextMetadataAttribute,IDbContext,ContextType,Person,PersonContext,behavior,ExportMetadataAttribute
Did you find out why this is happening, I just ran into the same problem....
ReplyDeleteFound the answer here.
ReplyDeletehttp://stackoverflow.com/questions/16415192/mef-why-are-identical-duplicates-of-one-and-the-same-exported-plugin-created