The thing that comes the closest in Simple Injector is the following:
container.ResolveUnregisteredType += (s, e) =>
{
Type type = e.UnregisteredServiceType;
if (type.IsGenericType &&
type.GetGenericTypeDefinition() == typeof(IRepository<>))
{
var args = type.GetGenericArguments();
e.Register(() => RepositoryFactory.GetInstance(args[0], configuration));
}
};
Another option is to move the creation of the repositories out of the RepositoryFactory
class (if possible). That could make it much easier, because in that case you could simplify the registration to the following:
// using SimpleInjector.Extensions;
container.RegisterOpenGeneric(typeof(IRepository<>), typeof(GenericRepository<>));
container.RegisterOpenGeneric(typeof(IRepository<,>), typeof(GenericRepository<,>));
container.RegisterOpenGeneric(typeof(ICompoundKeyRepository<,,>),
typeof(GenericCompoundKeyRepository<,,>));