MEF: What if I have multiple exports but need only one import?

别来无恙 提交于 2019-12-03 10:59:50

See this blog post for a discussion of this issue and some of the options you have. Also, Glenn Block has a blog post describing how to customize the container behavior with defaults.

In the case of MEF, if you have many Exports that will satisfy an Import, you have two options:

  1. Change your Import around to use [ImportMany]. Decide, at runtime, which of the Imports to use for your contract, potentially just picking the first, or one at random.
  2. Use [ImportMany] in conjunction with Metadata in order to decide which Import to use.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!