English 中文(简体)
如何使用MEF 处置财产
原标题:How to use MEF IsMultiple property
  • 时间:2012-05-08 15:21:02
  •  标签:
  • .net-4.0
  • mef

<>光线> 我曾试图把两个实施红十字与红新月联会的大会进口到我们中间。 这样做是毫无道理的,使用[ImportMany]进口所有给我一个数字可观的E。 然后,我的消费逻辑决定了根据MetaData“Bar”进口的大会的哪一部分。

每个出口商都与出口Metadata属性进行了校正。 如果我:

[Export(typeof(IFoo))]
[ExportMetadata("Bar", "Hello")]
public class Hello : IFoo
{...}

[Export(typeof(IFoo))]
[ExportMetadata("Bar", "World")]
public class World: IFoo
{...}

这就是说,我的国际电子计算方法有两处红十字与红新月。

如果不需要“Hello”或“World”,我想把“Default”作为我的Bar元数据。 我曾试图利用IsMultiple财产这样做:

[Export(typeof(IFoo))]
[ExportMetadata("Bar", "Hello", IsMultiple = true)]
[ExportMetadata("Bar", "Default", IsMultiple = true)]
public class Hello : IFoo
{...}

<<>Problem>: 当我加上IsMultiple property和第二属性时,Hello类不再被推入由此得出的数字。

Question: How do I tag a class for MEF with a second/default designation?

感谢!

最佳回答

为了揭露像这样一类的多种完全独立的出口,最好的办法就是使用多种财产出口,在这种情况下,这种出口会回来。

class Hello: IFoo
{
    [Export, ExportMetadata(...)]
    public IFoo Bar { get { return this; } }

    [Export, ExportMetadata(...)]
    public IFoo Default { get { return this; } }
}
问题回答

暂无回答




相关问题
Can t load multiple MEF parts

I have a Winforms desktop application that is loading multiple MEF parts with the same Interface type. Problem: When I try to load more than one of the same type I get the following exception: The ...

MEF + WCF Service Host?

I am just getting into MEF and I have come across a problem that I cannot resolve. I have a windows service that is reading in my DLLs (via MEF) and each DLL is a WCF Service Host. When I run my ...

MEF: Where should I put the CompositionContainer?

I have been using the Windsor IoC Container for my web-based application, to resolve the data access layer implementation the application should use. The web application s UI will consist of pages, ...

MEF如何确定其进口顺序?

MEF允许你通过使用进口管理特性进口多个部件。 如何确定它收回相关出口的顺序,并增加这些出口量,以达到你所知道的数量......

How-To Prevent Module Duplicates with MEF?

How can i prevent from MEF to load duplicates Modules in the case of the presence of 2 copies of the same Assembly (maybe by mistake) Assembly1.dll Assembly2.dll (copy of Assembly1) [ImportMany] ...

Basic MEF workflow/usage

I m looking to a framework which will allow me to have a simple plugin system in my .NET application. It seems MEF is the framework which Microsoft is endorsing, and will become part of .NET 4 (it ...

热门标签