加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

依赖注入 – Castle Windsor不能注入一系列接口类型

发布时间:2020-12-14 00:47:14 所属栏目:百科 来源:网络整理
导读:我有一个类在构造函数中接受一组接口: public class FooT1,T2 : IFooT1,T2{ public Foo(IBar[] bars) { ... }} 我的容器注册如下: container.Register(AllTypes.Pick().FromAssemblyNamed("...") .WithService.FirstInterface());container.AddComponent("
我有一个类在构造函数中接受一组接口:
public class Foo<T1,T2> : IFoo<T1,T2>
{
    public Foo(IBar[] bars)
    {
        ...
    }
}

我的容器注册如下:

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

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

但是,如果我尝试获得一个IFoo的实例,它会抛出一个异常,说它无法满足这个未被注册的“deoendency …”.

如果我更改构造函数以使单个IBar实例工作正常.

有任何想法吗?

添加ArrayResolver:
container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读