Unless I'm doing it wrong, it still seems like a lot of code though, when used with generic interfaces:
container.Register(Classes.FromThisAssembly().BasedOn(typeof (CommandExecutor<>))
.ConfigureIf(registration => registration.Implementation.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof (IHandleMessages<>)),
registration =>
{
var genericArgument = registration.Implementation.GetInterfaces()
.First(y => y.GetGenericTypeDefinition() == typeof (IHandleMessages<>))
.GetGenericArguments()[0];
registration.Forward(typeof (IHandleMessages<>).MakeGenericType(genericArgument));
})
.WithService.Base().LifestyleTransient(),
Classes.FromThisAssembly().BasedOn(typeof (IHandleMessages<>)).WithService.Base().LifestyleTransient());
Would it be meaningful to support multiple BasedOn or'ed together? Would you accept a patch?
//Asger