[InheritedExport] vs [Export] performance

Jun 10, 2010 at 10:27 PM

I noticed there is a [InheritedExport] attribute in addition to the [Export] attribute.

Other than stylistic reasons (e.g. declaring export at interface level vs explicit interface export on each concrete classes), is there a performance impact of using [InheritedExport]? Does MEF compose faster using one or the other, or is the performance difference negligible?

Thanks in advanced.

Jun 10, 2010 at 10:32 PM

Second question:

Is there a penalty of using both at the same time (e.g. an interface has the InheritedExport attribute while the concrete classes explicitly exports the interface using Export attribute)?

Jun 14, 2010 at 5:11 PM

As far as performance goes there isn't any difference between InheritedExport and Export while doing the catalog discovery, which is when this work is done not at composition time, because in both cases we have to look for InheritedExport and Export attributes.

First a little background on InheritedExport, its primary purpose is for legacy systems which used to just find all types that implement a given interface, this gives an easy migration path for such systems. The other use of it is for people who want to completely hide MEF from the extension authors.

Now with those two purposes in mind you generally should not mix and match InheritedExport and Export on the same type hierarchy and if you do you will actually get the extension exported more than once. It will be exported via the InheritedExport and the Export attribute, with potentially the same contract name. 

Jun 14, 2010 at 5:27 PM

I originally intended to use the InheritedExport attribute so that extension authors do not need to reference System.Composition. However, seeing how we are human and can easily forget, I see a case where the author adds the Export attribute even though the host application already decorates the extension interface with InheritedExport.

Thanks for the info weshaggard, I guess I'll just stick with the more common Export attribute.