internal ServiceRegistry CompileConfigurationAndServicesForIdiomaticBootstrapping() { _baseServices.Insert(0, ServiceDescriptor.Singleton <IHostedService, MessagingActivator>()); // Add services var options = new WebHostOptions(EnvironmentConfiguration); var contentRootPath = ResolveContentRootPath(options.ContentRootPath, AppContext.BaseDirectory); // Initialize the hosting environment // TODO -- Watch this, if there are bugs in bootstrapping!!!!!! _hostingEnvironment.Initialize(contentRootPath, options); _hostingEnvironment.ApplicationName = ApplicationAssembly.FullName; var context = new WebHostBuilderContext { Configuration = EnvironmentConfiguration, HostingEnvironment = _hostingEnvironment }; Services.AddSingleton(_hostingEnvironment); Services.AddSingleton(context); var builder = Configuration .SetBasePath(_hostingEnvironment.ContentRootPath) .AddInMemoryCollection(EnvironmentConfiguration.AsEnumerable()); foreach (var configureAppConfiguration in _configureAppConfigurationBuilderDelegates) { configureAppConfiguration(context, builder); } var configuration = builder.Build(); Services.AddSingleton <IConfiguration>(configuration); Services.AddSingleton <IConfigurationRoot>(configuration); context.Configuration = configuration; Settings.Bootstrap(new WebHostBuilderContext { HostingEnvironment = _hostingEnvironment, Configuration = configuration }); var listener = new DiagnosticListener("Microsoft.AspNetCore"); Services.AddSingleton(listener); Services.AddSingleton <DiagnosticSource>(listener); Services.AddTransient <IApplicationBuilderFactory, ApplicationBuilderFactory>(); Services.AddTransient <IHttpContextFactory, HttpContextFactory>(); Services.AddScoped <IMiddlewareFactory, MiddlewareFactory>(); Services.AddOptions(); Services.AddLogging(); Services.AddSingleton <Microsoft.AspNetCore.Hosting.IApplicationLifetime, ApplicationLifetime>(); // Conjure up a RequestServices // TODO -- want this to be optional Services.AddTransient <IStartupFilter, AutoRequestServicesStartupFilter>(); foreach (var configureServices in _configureServicesDelegates) { configureServices(context, Services); } var all = _baseServices.Concat(ExtensionServices).Concat(_applicationServices); var combined = new ServiceRegistry(); combined.AddRange(all); combined.For <IDurableMessagingFactory>().UseIfNone <NulloDurableMessagingFactory>(); combined.For <IServer>().UseIfNone <NulloServer>(); return(combined); }