创建进口MEF部件的多个实例多个、部件、实例、MEF

2023-09-03 06:29:49 作者:笑靥

目前我的WPF应用程序导入一部分像这样

Currently my WPF application imports a part like this

[Import(typeof(ILedPanel)]
public ILedPanel Panel { get; set; }

但是,这给了马实现ILedPanel类的单一intance。 我真正想要做的就是要创造尽可能多的实例的能力 我所需要的。请注意,包括的话,只有一个出口的ILedPanel 在任何给定时间的软件

But this gives ma a single intance of the class that implements ILedPanel. What I really want to do is have the ability to create as many instances that I need. Please note there is only one Export for ILedPanel included with the software at any given time.

(如果我使用的导入与列表这给了我一个实例 对于每一个类实现ILedPanel)

(If I use an import with List that gives me one instance for every class implementing ILedPanel)

有什么建议?

推荐答案

没有内置这在MEF支持的今天,但在此之前恢复到服务定位器,你可以在这里找到一些灵感:http://blogs.msdn.com/nblumhardt/archive/2008/12/27/container-managed-application-design-$p$plude-where-does-the-container-belong.aspx

There isn't "built in" support for this in MEF today, but before reverting to Service Locator, you might find some inspiration here: http://blogs.msdn.com/nblumhardt/archive/2008/12/27/container-managed-application-design-prelude-where-does-the-container-belong.aspx

的基本想法是,你'进口'的容器放入一个组成部分,需要做动态的实例。

The essential idea is that you 'import' the container into the component that needs to do dynamic instantiation.

对于这种情况更直接的支持是我们正在探索。

More direct support for this scenario is something we're exploring.

尼克

更新: MEF现在有这个实验支持。请参见这篇博客了解更多信息。

UPDATE: MEF now has experimental support for this. See this blog post for more information.