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>());
}
}
我到底做错了什么?我已经在MefInstaller
和ModuleAInstaller
类中尝试了不同的属性和合同名称。我也尝试使用CompositionBatch
组合零件,但没有成功。任何帮助是极大的赞赏!