开发者

How can I avoid redundant imports in MEF?

开发者 https://www.devze.com 2023-01-11 21:17 出处:网络
Here\'s the issue... if I use, say a directory catalog in MEF and have some.dll and copy of some.dll, i will get double the exports, even though they are defining the same type, is there a way to reso

Here's the issue... if I use, say a directory catalog in MEF and have some.dll and copy of some.dll, i will get double the exports, even though they are defining the same type, is there a way to resolve this?

EDIT: the problem isn't with this particular issue, this is just an abstract example of a real issue, for instance, if i have an "exten开发者_如何学Gosions" folder, and a way to manually import... it's just something that would be nice to handle.


You can do this with a FilteredCatalog (not part of the core MEF distribution.) See the example here: http://mef.codeplex.com/wikipage?title=Filtering%20Catalogs

Rather than selecting from the inner catalogs via Where you may use Distinct. To compare ComposablePartDefinitions for equality the simplest option is to use ToString but casting to ReflectionComposablePartDefinition is also an option.

HTH, Nick


is there a way to resolve this?

Two options come to mind:

  • remove the redundant copy of the assembly
  • don't use a directory catalog. You can add assembly catalogs for each individual assembly, and just leave out the unwanted assemblies.
0

精彩评论

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