开发者

How to use MEF's GetExport\ImportDefinition?

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!


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

See these articles and blog posts for details:

  • Building Hello MEF – Part II – Metadata and why being Lazy is a good thing.
  • MEF for beginner - Part 8 - Metadata
  • Providing metadata to your MEF exports
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜