Exemple #1
0
        public IServiceProvider CreateServiceProvider(Container container)
        {
            Services.UseSimpleInjectorAspNetRequestScoping(container);

            Services.AddSingleton <IControllerActivator>(new SimpleInjectorControllerActivator(container));

            Services.AddSingleton <IViewComponentActivator>(new SimpleInjectorViewComponentActivator(container));

            Services.EnableSimpleInjectorCrossWiring(container);

            var defaultServiceProvider = Services.BuildServiceProvider();

            container.RegisterMvcControllers(new ApplicationBuilder(defaultServiceProvider));

            container.RegisterMvcViewComponents(new ApplicationBuilder(defaultServiceProvider));

            var compositeServiceProvider = new CompositeServiceProvider(defaultServiceProvider, Container);

            var compositeServiceScopeFactory = new CompositeServiceScopeFactory(container, defaultServiceProvider.GetService <IServiceScopeFactory>());

            container.RegisterSingleton <IServiceScopeFactory>(compositeServiceScopeFactory);

            container.ConfigureAutoCrossWiring(defaultServiceProvider, Services);

            return(compositeServiceProvider);
        }
 public CompositeServiceScope(Container container, IServiceScope defaultServiceScope)
 {
     // for scoping we want to provide MS child container with simple injector.
     ServiceProvider      = new CompositeServiceProvider(defaultServiceScope.ServiceProvider, container);
     _defaultServiceScope = defaultServiceScope;
 }