You can have multiple registrations. Here is an example (apologies but my PC died today and I am writing this in notepad):
SimpleInjectorContainer.RegisterManyForOpenGeneric(typeof(CommandHandler<>),
AccessibilityOption.PublicTypesOnly,
(serviceType, implTypes) => container.RegisterAll(serviceType, implTypes),
AppDomain.CurrentDomain.GetAssemblies()
);
and they can be retrieved with:
public IEnumerable<CommandHandler<T>> GetHandlers<T>()
where T : class
{
return SimpleInjectorContainer.GetAllInstances<CommandHandler<T>>();
}
you'll find these versions of the RegisterManyForOpenGeneric
and GetAllInstances
methods described here
I use this technique to support a publish/subscribe framework. You can have n number of independent CommandHandler
's