2016-08-12 61 views
0

我已经使用下面的链接进行城堡windsor依赖注入。我无法注册该组件。无法注册城堡windsor中的组件

http://www.codeproject.com/Tips/1052382/ASP-NET-MVC-Dependency-Injection-using-Windsor#_comments

public class ServiceInstaller : IWindsorInstaller 
{ 
    public void Install(Castle.Windsor.IWindsorContainer container, 
         Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store) 
    { 
     container.Register(
      Component.For<Interfaces.TestInterface>() 
        .ImplementedBy<Services.TestServices>() 
        .LifestyleTransient()); 
    } 
} 

的ErrorMessage:

的类型 'Castle.MicroKernel.ComponentRegistrationException' 的异常出现在 Castle.Windsor.dll但在用户代码中没有处理

附加信息:组件 TestForCastleWindsor.Services.TestServices could n不被注册。 已经有一个具有该名称的组件。您是否想要修改 现有组件?如果不是,请确保您指定一个唯一的 名称。

+0

您确定您还没有在其他地方注册组件吗?您在任何地方的注册管道上没有任何定制? – Charleh

+0

我还没有在其他地方注册的组件 – user2465036

+0

公共类ControllersInstaller:。IWindsorInstaller { 公共无效安装(IWindsorContainer容器,IConfigurationStore店) { container.Register( 类 FromThisAssembly() 支持算法FMP () 如果(c => c.Name.EndsWith(“Controller”))。 LifestyleTransient()); ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container)); } } – user2465036

回答

0

该组件正在被注册两次。按照惯例,当IWindsorInstaller实现或组件被拾起时,可能会发生这种情况。例如,为了实现IWindsorInstaller而扫描目录中的所有程序集,并且存在旧的重复程序集。或者您的组件实现的另一个接口的所有实现都已预先注册。