/// <summary> /// Registers the specified concrete type for resolve with delegate for concrete implementation instance creation. /// </summary> /// <typeparam name="TService">Service type.</typeparam> /// <param name="instanceCreator">The instance creator.</param> /// <param name="lifetimeType">Lifetime type of the registering concrete type.</param> public void Register <TService>(Func <IDIContainerProvider, TService> instanceCreator, LifetimeType lifetimeType = LifetimeType.PerLifetimeScope) where TService : class { switch (lifetimeType) { case LifetimeType.Transient: Container.RegisterDelegate(c => { var provider = new DryIocDIProvider { Container = (Container)c }; return(instanceCreator(provider)); }, Reuse.Transient); break; case LifetimeType.Singleton: Container.RegisterDelegate(c => { var provider = new DryIocDIProvider { Container = (Container)c }; return(instanceCreator(provider)); }, Reuse.Singleton); break; case LifetimeType.PerLifetimeScope: Container.RegisterDelegate(c => { var provider = new DryIocDIProvider { Container = (Container)c }; return(instanceCreator(provider)); }, Reuse.InCurrentScope); break; } }
/// <summary> /// Initializes a new instance of the <see cref="DryIocLifetimeScope"/> class. /// </summary> /// <param name="provider">The provider.</param> public DryIocLifetimeScope(DryIocDIProvider provider) { _context = provider.Container.OpenScope(); Resolver = new DryIocDIResolver(_context); }