2
votes

I have used the below link for the castle windsor dependency injection.I am not able to register the component.

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:

An exception of type 'Castle.MicroKernel.ComponentRegistrationException' occurred in Castle.Windsor.dll but was not handled in user code

Additional information: Component TestForCastleWindsor.Services.TestServices 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.

1
Are you sure you haven't registered the component already somewhere else? You don't have any customisation on the registration pipeline anywhere?Charleh
I have not registered the component elsewhereuser2465036
public class ControllersInstaller : IWindsorInstaller { public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( Classes. FromThisAssembly(). BasedOn<IController>(). If(c => c.Name.EndsWith("Controller")). LifestyleTransient()); ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container)); } }user2465036
Just before the registration line, put a breakpoint on, you can inspect the container and it has a list of registered services and their associated implementationsCharleh

1 Answers

0
votes

That component is being registered twice. This can happen when IWindsorInstaller implementations or components are picked up by convention. For example, all assemblies in a directory are scanned for implementations of IWindsorInstaller and an old duplicate assembly is present. Or all implementations of another interface also implemented by your component are previously registered.