我使用以下链接进行城堡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。 已有一个具有该名称的组件。你想修改吗? 相反,现有的组件?如果没有,请确保指定唯一 名。
答案 0 :(得分:0)
该组件正在注册两次。当按惯例拾取IWindsorInstaller实现或组件时,可能会发生这种情况。例如,扫描目录中的所有程序集以查找IWindsorInstaller的实现,并且存在旧的重复程序集。或者,组件实现的另一个接口的所有实现都已预先注册。