I'm using Commands and CommandHandlers with Castel Windsor registration. There are some examples:
//command
public class DeleteEntityComand : ICommand
{
public int Id { get; set; }
}
//command handler
public class DeleteEntityCommandHandler : ICommandHandler<DeleteEnityComand>
{
...
}
//registrations
Types.FromAssembly(Assembly.GetAssembly(typeof(DeleteEntityCommandHandler)))
.BasedOn(typeof(ICommandHandler<>))
.WithService.AllInterfaces().LifestyleTransient()
And it works perfect. But now I want to use generic command handler like this:
//command
public class SoftRemoveCommand<T> : ICommand
{
public int Id { get; set; }
}
//command handler
public class SoftRemoveCommandHandler<T> : ICommandHandler<SoftRemoveCommand<T>>
{
..
}
But unfortunately in this case previous registration doesn't work. It tries to resolve my abstract BaseCommandHandler which is also implements ICommandHandler interface. So how can I register my generic command handlers properly?
Update:
After adding WithService.Base:
//registrations
Types.FromAssembly(Assembly.GetAssembly(typeof(DeleteEntityCommandHandler)))
.BasedOn(typeof(ICommandHandler<>))
.WithService.AllInterfaces()
.WithService.Base()
.LifestyleTransient()
Castle is trying to resolve SoftRemoveCommandHandler<SoftRemoveCommand<T>>
but not SoftRemoveCommandHandler<T>
and it throws an exception "Coul not proxy".
Is it possible to make Castle resolve SoftRemoveCommandHandler<T>
, not SoftRemoveCommandHandler<SoftRemoveCommand<T>>
?