示例#1
0
        public static IWebHostBuilder UseUnityServiceProvider(this IWebHostBuilder hostBuilder, IUnityContainer container = null)
        {
            _factory = new ServiceProviderFactory(container);

#if NETCOREAPP1_1
            return(hostBuilder.ConfigureServices((services) =>
            {
                services.Replace(ServiceDescriptor.Singleton <IServiceProviderFactory <IUnityContainer> >(_factory));
                services.Replace(ServiceDescriptor.Singleton <IServiceProviderFactory <IServiceCollection> >(_factory));
            }));
#else
            return(hostBuilder.ConfigureServices((context, services) =>
            {
                services.Replace(ServiceDescriptor.Singleton <IServiceProviderFactory <IUnityContainer> >(_factory));
                services.Replace(ServiceDescriptor.Singleton <IServiceProviderFactory <IServiceCollection> >(_factory));
            }));
#endif
        }