Reputation: 17388
I am trying to port some structuremap code to castle windor. At the moment, I am getting this error:
No component for supporting the service CreateTestCommandHandler was found
I am using a console app to test things:
Console app:
private static IWindsorContainer _container;
...
static void Main()
{
_container = new WindsorContainer();
ApplicationBootStrapperCastleWindsor.BootStrap(_container);
...
Some more abbreviated code:
public class CreateTestCommandHandler : ICommandHandler<CreateTestCommand>
{
private readonly IDomainRepository<IDomainEvent> _repository;
public CreateTestCommandHandler(IDomainRepository<IDomainEvent> repository)
{
_repository = repository;
}
...
and:
public class ApplicationBootStrapperCastleWindsor
{
public void BootStrapTheApplication(IWindsorContainer container)
{
container.Install(new DomainInstaller());
}
public static void BootStrap(IWindsorContainer container)
{
new ApplicationBootStrapperCastleWindsor().BootStrapTheApplication(container);
}
}
and:
public class DomainInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<IDomainRepository<IDomainEvent>>().ImplementedBy<DomainRepository<IDomainEvent>>());
Can someone see anything obvious wrong? Inspecting the container I also get IDomainRepository in potentially reconfigured components.
The original structuremap code is as follows:
ForRequestedType<IDomainRepository<IDomainEvent>>()
.TheDefault.Is.OfConcreteType<DomainRepository<IDomainEvent>>();
PS:
The actual exception is thrown in GetCorrectlyInjectedCommandHandler (original structuremap code can be found here):
public class RegisterCommandHandlersInMessageRouter
{
private static IWindsorContainer _container;
public static void BootStrap(IWindsorContainer container)
{
_container = container;
new RegisterCommandHandlersInMessageRouter().RegisterRoutes(new MessageRouter());
}
private static object GetCorrectlyInjectedCommandHandler(Type commandHandler)
{
return _container.Resolve(commandHandler);
}
}
Upvotes: 0
Views: 103
Reputation: 23747
It seems like you're misunderstanding how Windsor finds your components. You can either register components explicitly (like you did for IDomainRepository<IDomainEvent>
in your DomainInstaller
), or you can register all types in an assembly (for example) by convention. Either way, if you don't tell Windsor about your type it will throw the exception that you received.
Take a look at registration by convention, it tends to be an easy place to start and can reduce a lot of maintenance moving forward. You can override any auto-registrations by performing manual registrations (again like you did above) if you need to change lifestyles or other properies of specific components.
I don't know much about StructureMap but I see it has similar auto-registration functionality that you may already be using.
Upvotes: 1