我在试着对一个计划员进行单元测试。
//Arrange
var containter = new WindsorContainer();
var Orch = containter.Resolve<ApiOrchestrator>();// Exception Thrown hereOrchestrator的构造器是:
public ApiOrchestrator(IApiWrap[] apiWraps)
{
_apiWraps = apiWraps;
}登记是
public class IocContainer : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<FrmDataEntry>().LifestyleTransient());
container.Register(Component.For<ApiOrchestrator>().LifestyleTransient());
container.Register(Component.For<IApiWrap>().ImplementedBy<ClassA>().LifestyleTransient());
container.Register(Component.For<IApiWrap>().ImplementedBy<ClassB>().LifestyleTransient());
}
}IocContainer在正在测试的项目中,但是名称空间是引用的,我可以使用Orchestrator作为new。我希望它只给我所有已注册IApiWrap的数组。
作为卡塞尔的新手,我不明白缺少了什么。代码修复会很好,但我真的很想知道为什么容器似乎没有注册的编排器。
发布于 2016-02-23 17:51:53
好的,少了3样东西
安装程序更改
public class IocContainer : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
//New Line
container.Kernel.Resolver.AddSubResolver(
new CollectionResolver(container.Kernel, true));
container.Register(Component.For<FrmDataEntry>().LifestyleTransient());
container.Register(Component.For<ApiOrchestrator>().LifestyleTransient());
container.Register(Component.For<IApiWrap>().ImplementedBy<SettledCurveImportCommodityPriceWrap>().LifestyleTransient());
container.Register(Component.For<IApiWrap>().ImplementedBy<ForwardCurveImportBalmoPriceWrap>().LifestyleTransient());
}
}测试/解决变化
//Arrange
var container = new WindsorContainer();
//New Line
container.Install(FromAssembly.InDirectory(new AssemblyFilter("","EkaA*") ));
var Orch = container.Resolve<ApiOrchestrator>();现在,它可以工作了,尽管对代码所做的任何进一步解释或更正都是值得欢迎的。
https://stackoverflow.com/questions/35583153
复制相似问题