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
組合零件,但沒有成功。任何幫助是極大的讚賞!