Castle Windsor无法注入一系列接口类型 [英] Castle Windsor can't inject an array of interface types
本文介绍了Castle Windsor无法注入一系列接口类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类在构造函数中接受一组接口:
I have a class that takes an array of interfaces in the constructor:
public class Foo<T1, T2> : IFoo<T1, T2>
{
public Foo(IBar[] bars)
{
...
}
}
我的容器注册如下所示:
My container registration looks as follows:
container.Register(AllTypes.Pick().FromAssemblyNamed("...")
.WithService.FirstInterface());
container.AddComponent("foo", typeof(IFoo<,>), typeof(Foo<,>));
我有几个实现的IBar,容器可以肯定地找到它们,调用 ServiceLocator.Current.GetAllInstances< IBar>()
工作正常。
I have several implementations of IBar, and the container can definately locate them, as calling ServiceLocator.Current.GetAllInstances<IBar>()
works fine.
但是,如果我尝试获取一个IFoo,它引发了一个例外,说它无法满足这个deoendency ...没有注册。
如果我更改构造函数
任何想法?
推荐答案
p>添加ArrayResolver:
Add the ArrayResolver:
container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));
这篇关于Castle Windsor无法注入一系列接口类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文