/// <summary>
        /// Creates Simplify.DI wrapper service provider for Microsoft.Extensions.DependencyInjection
        /// </summary>
        /// <param name="provider">The resolver.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">collection</exception>
        public static IServiceProvider CreateServiceProvider(this IDIContainerProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            var serviceProvider = new DIServiceProvider(provider);

            // Registering required IOC container types wrappers in itself

            provider.Register <IServiceProvider>(x => serviceProvider, LifetimeType.Singleton);
            provider.Register <IServiceScopeFactory>(x => new DIServiceScopeFactory(provider), LifetimeType.Singleton);

            return(serviceProvider);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DIServiceScope"/> class.
 /// </summary>
 /// <param name="contextHandler">The context handler.</param>
 public DIServiceScope(IDIContextHandler contextHandler)
 {
     _scope          = contextHandler.BeginLifetimeScope();
     ServiceProvider = new DIServiceProvider(_scope.Resolver);
 }