Castle Windsor无法注入一系列接口类型

Chr*_*nes 12 dependency-injection castle-windsor

我有一个类,它在构造函数中接受一组接口:

public class Foo<T1, T2> : IFoo<T1, T2>
{
    public Foo(IBar[] bars)
    {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

我的容器注册如下:

container.Register(AllTypes.Pick().FromAssemblyNamed("...")
                    .WithService.FirstInterface());
container.AddComponent("foo", typeof(IFoo<,>), typeof(Foo<,>));
Run Code Online (Sandbox Code Playgroud)

我有几个IBar的实现,容器可以定义它们,因为调用ServiceLocator.Current.GetAllInstances<IBar>()工作正常.

但是,如果我试图获得一个IFoo的实例,它会抛出一个异常,说它无法满足deoendency ..."哪个没有注册".

如果我改变构造函数以获取IBar的单个实例,它可以正常工作.

有任何想法吗?

Mau*_*fer 23

添加ArrayResolver:

container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel)); 
Run Code Online (Sandbox Code Playgroud)