Windsor可以注入组件列表吗?

时间:2010-04-20 06:05:19

标签: castle-windsor

考虑这个例子:

    public class Factory
    {
        private List<ISubFactory> subFactories;

        public Factory(List<ISubFactory> subFactories)
        {
            this.subFactories = subFactories;
        }
    }

    public interface ISubFactory
    {

    }

我希望Windsor解析Factory类并将容器中注册的ISubFactory接口的所有实现者(ResolveAll)放入“subFactories”参数中,Windsor可以这样做吗?

1 个答案:

答案 0 :(得分:8)

是的,它可以。但是你必须首先选择注册ListResolver

container.Kernel.Resolver.AddSubResolver(new ListResolver(container.Kernel));