Eagerly initialize hosting environment

This commit is contained in:
jacalvar 2016-04-01 23:08:21 -07:00
parent b6a3fee088
commit 4cbda0358b
1 changed files with 8 additions and 9 deletions

View File

@ -159,15 +159,8 @@ namespace Microsoft.AspNetCore.Hosting
var hostingServices = BuildHostingServices();
var hostingContainer = hostingServices.BuildServiceProvider();
var appEnvironment = hostingContainer.GetRequiredService<IApplicationEnvironment>();
var startupLoader = hostingContainer.GetRequiredService<IStartupLoader>();
var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, appEnvironment.ApplicationBasePath);
var applicationName = ResolveApplicationName() ?? appEnvironment.ApplicationName;
// Initialize the hosting environment
_hostingEnvironment.Initialize(applicationName, contentRootPath, _options);
var host = new WebHost(hostingServices, startupLoader, _options, _config);
// Only one of these should be set, but they are used in priority
@ -184,6 +177,14 @@ namespace Microsoft.AspNetCore.Hosting
{
_options = new WebHostOptions(_config);
var defaultPlatformServices = PlatformServices.Default;
var appEnvironment = defaultPlatformServices.Application;
var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, appEnvironment.ApplicationBasePath);
var applicationName = ResolveApplicationName() ?? appEnvironment.ApplicationName;
// Initialize the hosting environment
_hostingEnvironment.Initialize(applicationName, contentRootPath, _options);
var services = new ServiceCollection();
services.AddSingleton(_hostingEnvironment);
@ -218,8 +219,6 @@ namespace Microsoft.AspNetCore.Hosting
// Ensure object pooling is available everywhere.
services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
var defaultPlatformServices = PlatformServices.Default;
services.AddSingleton(defaultPlatformServices.Application);
services.AddSingleton(defaultPlatformServices.Runtime);