/// <summary>
        /// Adds the host factory for asp net core
        /// </summary>
        /// <param name="builder">The testing server builder</param>
        /// <param name="configureOptions">Configures options.</param>
        /// <param name="configure">Configuration delegate for the web host</param>
        /// <returns>The testing server builder</returns>
        public static TestingServerBuilder AddAspNetCoreHostFactory(this TestingServerBuilder builder, Action <AspNetCoreHostOptions> configureOptions, Action <IWebHostBuilder> configure)
        {
            var channel = new LogMessageChannel();

            var c = new Action <IWebHostBuilder>(webHost =>
            {
                configure(webHost);
                webHost
                .ConfigureServices((context, services) =>
                {
                    var descriptor = ServiceDescriptor.Singleton <IServiceProviderFactory <IServiceCollection> >(new TestingServiceProviderFactory(context.Configuration, channel));
                    services.Replace(descriptor);
                })
                ;
            });

            builder
            .ConfigureAspNetCoreHost(configureOptions)
            .AddTestingServices(services =>
            {
                services.RemoveAll <LogMessageChannel>();
                services.RemoveAll <LogMessageReader>();
                services.AddSingleton(channel);
                services.AddSingleton <LogMessageReader>();
                services.AddSingleton <IWebHostOptionsProvider>(new WebHostOptionsProvider {
                    Configure = c
                });
                services.TryAddSingleton <IWebHostFactory, DefaultWebHostFactory>();
            })
            ;

            return(builder.AddHostFactory <AspNetCoreInMemoryHostFactory>());
        }
 public TestingServiceProviderFactory(IConfiguration configuration, LogMessageChannel channel)
 {
     _configuration = configuration;
     _channel       = channel;
 }