如果我有接口和实现类,比如
public interface IA {}
public class X : IA {}
public class Y : IA {}
那么这个注册就好了
var w = new WindsorContainer();
w.Register(Component.For<IA>().ImplementedBy<X>());
w.Register(Component.For<IA>().ImplementedBy<Y>());
如同
var w = new WindsorContainer();
w.Register(Component.For<IA>().Instance(new X()));
w.Register(Component.For<IA>().Instance(new Y()));
但是,如果我尝试将具体类注册为
var w = new WindsorContainer();
var x1 = new X();
var x2 = new X();
w.Register(Component.For<X>().Instance(x1));
w.Register(Component.For<X>().Instance(x2));
它抛出一个异常:Castle.MicroKernel.ComponentRegistrationException : Component X could not be registered. There is already a component with that name. Did you want to modify the existing component instead? If not, make sure you specify a unique name.
如果这是有意的限制 - 为什么?有没有什么方法可以在不添加并不总是需要的接口的情况下实现集合解析?