Документы Simple Injector описывают , как реализовать ленивую зависимость. Однако этот пример охватывает только регистрацию простого интерфейса (IMyService
). Как это будет работать с открытым универсальным (EG. IMyService<T>
)?
Вот моя существующая регистрация:
container.Register(typeof(IDbRepository<>), typeof(DbRepository<>));
Очевидно, что следующий код не компилируется, так как я не указываю универсальный тип:
container.Register(typeof(IDbRepository<>),
() => new LazyDbRepositoryProxy<>(new Lazy<IDbRepository<>(container.GetInstance<>)));
Возможно ли это в простом инжекторе? Я вижу только следующие переопределения для Register, не позволяющие передавать func / instanceCreator в:
public void Register(Type openGenericServiceType, params Assembly[] assemblies);
public void Register(Type openGenericServiceType, IEnumerable<Assembly> assemblies);
public void Register(Type openGenericServiceType, Assembly assembly, Lifestyle lifestyle);
public void Register(Type openGenericServiceType, IEnumerable<Assembly> assemblies, Lifestyle);
public void Register(Type openGenericServiceType, IEnumerable<Type> implementationTypes, Lifestyle);
public void Register(Type openGenericServiceType, IEnumerable<Type> implementationTypes);