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

Overriding an Export with a New One

Mar 6, 2010 at 12:48 AM

I could be missing the point...or not quite getting things...but here's my question.

I have my base implementation assembly, which will IMPORT a Config-class (that contains some config values), and an implementation of this exists in the same base-assembly.  This is so I have by default some values to work with.

Then, I want the consumer of this assembly to EXPORT their own version of this Config-class, effectively overriding my default implementation.

What I'm not sure of is how to override the initial import, which is registered within the catalog by default in the base-implementation.  If I let both exist, then I'll get a resolution error when I try to do the import.

What's the approach here?  Thanks (and sorry if this is a misguided question).


[PS: I'm doing this in Silverlight, if that has any impact on the approach].

Mar 10, 2010 at 6:24 AM
Edited Mar 10, 2010 at 6:25 AM

I think you might consider creating a custom MEF "ExportProvider" that encapsulates the logic to filter/select between your Parts.  A search should bring up some articles on this.

Alternatively, you could use ExportManyAttribute and satisfy the Import with multiple (config) Parts.  Then choose between them via metadata, or by data within the Part itself.

-- Alex Hoffman


Mar 10, 2010 at 6:57 AM
Edited Mar 10, 2010 at 6:57 AM

ExportMany? Alex are you working on a part of MEF I don't know about  :-)

You may not need a custom MEF export provider as we support a prioritization of exports with our existing AggregateExportProvider. It would allow overriding as you described. Check this post for more:



Mar 10, 2010 at 8:10 AM

Oops, I meant ImportMany of course.  I must have been channeling Export's exasperation at Import getting all the love


Mar 10, 2010 at 8:16 AM

That's awesome :-) And well said.

Apr 4, 2010 at 7:30 PM

G'day Glenn!

Sorry for the delay - getting back into this now.  Appreciate the explanation around AggregateExportProvider.  Hopefully that'll do it.