2016-08-12 65 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而掃描目錄中的所有程序集,並且存在舊的重複程序集。或者您的組件實現的另一個接口的所有實現都已預先註冊。