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

后端 未结 2 1814
青春惊慌失措
青春惊慌失措 2021-02-13 13:04

I\'m trying to wrap my mind around MEF. There is one thing I don\'t understand.

Assume that I have an interface, named ISomething, which is a contract, and I have more t

相关标签:
2条回答
  • 2021-02-13 13:25

    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.

    0 讨论(0)
  • 2021-02-13 13:30

    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.
    0 讨论(0)
提交回复
热议问题