Jul 7, 2009 at 11:46 PM
Edited Jul 7, 2009 at 11:48 PM
I was looking at a way to export certain types without having to mark them with the Export attribute. I found the different threads and blogs on creating custom programming models and even looked at the contrib project.
At one point I started playing around with ParthExportsInheritedAttribute since it would have allowed us to do almost what I wanted but without having to depart from the attributed model that was working quite well.
When doing my own tests I realized that metadata on subclasses wasn't being consumed. I then found the following in the MEF Preview 5 test code:
public abstract class BaseClassWithExportButNoMetadata
public class DerivedClassMetadataButNoExport : BaseClassWithExportButNoMetadata
public void Metadata_BaseClassWithExportButNoMetadata()
var container = ContainerFactory.CreateWithAttributedCatalog(
var export = container.GetExport<BaseClassWithExportButNoMetadata>();
Assert.IsFalse(export.Metadata.ContainsKey("Name"), "Export should only contain metadata from the base!");
I found that rather counter-intuitive. In our case, the type exported with the PartExportsInheritedAttribute is an abstract base class, and the different implementation are all marked with a series of attributes that are themselves marked ExportMetadata.
I was naturally expecting to be able to have all that metadata available, but I guess MEF is not going to provide that.
What is the rational behind that?
And also, is there any other way to define exports through custom attributes without implementing a new model? (probably I'm missing something, but I couldn't see how implementing an ExportProvider would help me either)