tags:

views:

21

answers:

1

MEF n00b here.

I've got main project, and a series of dll's that have specific implementations of some interfaces as well as view\viewmodels, etc. I use {ImportMany] to get them all with some metadata, which allows me to choose one, which gives me a reference to the specific implementation of ISystem.

I'd like to get the only specific implementation of IDisplay from whatever dll the ISystem is chosen from, which I marked with [Export("SomeDisplay", typeof(IDisplay))] So far, the only thing that I can find that looks like it might work is GetExports(ImportDefinition), but I don't understand how to create an ImportDefinition that would work, as it seems to want a specific contractname, which isn't known until runtime.

Of course since I'm still a MEF n00b, it's a good bet I'm doing it wrong :D So, if GetExports is the best way, how can I make it work? Or is there a better way I should be using?

Thanks!

+2  A: 

You need to look into providing metadata along with your MEF exports.

See these articles and blog posts for details:

marc_s
I use metadata in my ISystem exports to provide some descriptive text so the user can choose which one to load. I'll give it a try. In what situations would I want to use GetExports?
Kage