2014-10-28 109 views
0

我基本上试图实现的是将MEF和Castle Windsor结合起来。 但我碰巧无法开始使用MEF。问题是,当我在MefInstaller类中的compositionContainer上拨打ComposeParts时,由于某种原因,它不会填充installers收藏夹。如何使用MEF和DirectoryCatalog填充对象的IEnumerable-Property属性

DirectoryCoatalog单词正常,并正确加载所需文件(包括ModuleA.dll)。

public class MefInstaller : IWindsorInstaller 
{ 
    [ImportMany] 
    public IEnumerable<IWindsorInstaller> installers { get; set; } // here the Exported Objects should be stored 

    public void Install(IWindsorContainer container, IConfigurationStore store) 
    { 
     var directory = Environment.CurrentDirectory; 

     var directoryCatalog = new DirectoryCatalog(directory); 
     var compositionContainer = new CompositionContainer(directoryCatalog); 

     compositionContainer.ComposeParts(this); 

     foreach (var windsorInstaller in installers) 
     { 
      windsorInstaller.Install(container, store); 
     } 

     Console.WriteLine("List in Field : {0}", installers.Count()); 
    } 
} 

的类导入看起来如下:

[Export("ComponentInstaller")] 
public class ModuleAInstaller : IWindsorInstaller 
{ 
    public void Install(IWindsorContainer container, IConfigurationStore store) 
    { 
     container 
      .Register(Component.For<IFoo>().ImplementedBy<FooA>()) 
      .Register(Component.For<IBar>().ImplementedBy<BarA>()); 
    } 
} 

我到底做错了什么?我已经在MefInstallerModuleAInstaller类中尝试了不同的属性和合同名称。我也尝试使用CompositionBatch组合零件,但没有成功。任何帮助是极大的赞赏!

回答

0

没关系,我解决了它。问题是ModuleAInstaller-Class上的属性。

一切工作正常使用

[Export(typeof(IWindsorInstaller))] 
public class ModuleAInstaller : IWindsorInstaller 
{ 
    [...] 
} 
相关问题