How does MEF determine the order of its imports?

后端 未结 3 462
野趣味
野趣味 2020-12-28 17:44

MEF allows you to import multiple parts via the use of the ImportMany attribute. How does it determine the order in which it retrieves the relevant exports and

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 18:08

    The best way to achieve this ordering in MEF is to utilize our metadata facilities. You can attach your own metadata to exports which you can use for ordering and filtering. Metadata also allows you to delay instantiation of parts until they are actually needed. Additionally you can create custom Export attributes which provide a nice clean way of providing the metadata.

    Check this link for information on how to define metadata and custom exports: link text

    You may also find this thread on our MEF forums useful. Within you'll find a discussion about an AdaptingCollection approach which lets you use a custom collection which applies a metadata filter / order.

    HTH Glenn

提交回复
热议问题