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

后端 未结 2 1813
青春惊慌失措
青春惊慌失措 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: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.

提交回复
热议问题