简体   繁体   English

如何避免MEF中的多余导入?

[英]How can I avoid redundant imports in MEF?

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? 这是问题...如果我使用,说MEF中的目录编目并有some.dll和some.dll的副本,我会得到双倍的导出,即使他们定义相同的类型,有没有办法解决这个?

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 "extensions" 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 您可以使用FilteredCatalog (不是核心MEF发行版的一部分)来执行此操作。请参阅此处的示例: http//mef.codeplex.com/wikipage?title = Filtering%20Catalogs

Rather than selecting from the inner catalogs via Where you may use Distinct . 而不是从内部目录中选择通过Where可以使用Distinct To compare ComposablePartDefinition s for equality the simplest option is to use ToString but casting to ReflectionComposablePartDefinition is also an option. 要比较ComposablePartDefinition的相等性,最简单的选择是使用ToString但也可以选择转换为ReflectionComposablePartDefinition

HTH, Nick HTH,尼克

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. 您可以为每个单独的程序集添加程序集目录,只需省略不需要的程序集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM