public IServiceProvider CreateServiceProvider(Container container)
        {
            _serviceProviderFactoryOptionsAction?.Invoke(_serviceProviderFactoryOptions);

            Services.UseSimpleInjectorAspNetRequestScoping(container);

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

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

            Services.EnableSimpleInjectorCrossWiring(container);

            var defaultServiceProvider = Services.BuildServiceProvider(_serviceProviderFactoryOptions.ValidateScope);

            container.RegisterMvcControllers(new ApplicationBuilder(defaultServiceProvider));

            if (_serviceProviderFactoryOptions.InclueViewComponents)
            {
                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;
 }