Move default config to Hosting.Abstractions
This commit is contained in:
parent
e72924796e
commit
294e16732f
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Hosting
|
||||||
|
{
|
||||||
|
public static class WebApplicationDefaults
|
||||||
|
{
|
||||||
|
public static readonly string ApplicationKey = "application";
|
||||||
|
public static readonly string DetailedErrorsKey = "detailedErrors";
|
||||||
|
public static readonly string EnvironmentKey = "environment";
|
||||||
|
public static readonly string ServerKey = "server";
|
||||||
|
public static readonly string WebRootKey = "webroot";
|
||||||
|
public static readonly string CaptureStartupErrorsKey = "captureStartupErrors";
|
||||||
|
public static readonly string ServerUrlsKey = "server.urls";
|
||||||
|
public static readonly string ApplicationBaseKey = "applicationBase";
|
||||||
|
|
||||||
|
public static readonly string HostingJsonFile = "hosting.json";
|
||||||
|
public static readonly string EnvironmentVariablesPrefix = "ASPNET_";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,13 +21,13 @@ namespace Microsoft.AspNet.Hosting.Internal
|
||||||
throw new ArgumentNullException(nameof(configuration));
|
throw new ArgumentNullException(nameof(configuration));
|
||||||
}
|
}
|
||||||
|
|
||||||
Application = configuration[WebApplicationConfiguration.ApplicationKey];
|
Application = configuration[WebApplicationDefaults.ApplicationKey];
|
||||||
DetailedErrors = ParseBool(configuration, WebApplicationConfiguration.DetailedErrorsKey);
|
DetailedErrors = ParseBool(configuration, WebApplicationDefaults.DetailedErrorsKey);
|
||||||
CaptureStartupErrors = ParseBool(configuration, WebApplicationConfiguration.CaptureStartupErrorsKey);
|
CaptureStartupErrors = ParseBool(configuration, WebApplicationDefaults.CaptureStartupErrorsKey);
|
||||||
Environment = configuration[WebApplicationConfiguration.EnvironmentKey] ?? configuration[OldEnvironmentKey];
|
Environment = configuration[WebApplicationDefaults.EnvironmentKey] ?? configuration[OldEnvironmentKey];
|
||||||
ServerFactoryLocation = configuration[WebApplicationConfiguration.ServerKey];
|
ServerFactoryLocation = configuration[WebApplicationDefaults.ServerKey];
|
||||||
WebRoot = configuration[WebApplicationConfiguration.WebRootKey];
|
WebRoot = configuration[WebApplicationDefaults.WebRootKey];
|
||||||
ApplicationBasePath = configuration[WebApplicationConfiguration.ApplicationBaseKey];
|
ApplicationBasePath = configuration[WebApplicationDefaults.ApplicationBaseKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Application { get; set; }
|
public string Application { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
throw new ArgumentNullException(nameof(assemblyName));
|
throw new ArgumentNullException(nameof(assemblyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
return applicationBuilder.UseSetting(WebApplicationConfiguration.ServerKey, assemblyName);
|
return applicationBuilder.UseSetting(WebApplicationDefaults.ServerKey, assemblyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IWebApplicationBuilder UseServer(this IWebApplicationBuilder applicationBuilder, IServer server)
|
public static IWebApplicationBuilder UseServer(this IWebApplicationBuilder applicationBuilder, IServer server)
|
||||||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
throw new ArgumentNullException(nameof(applicationBasePath));
|
throw new ArgumentNullException(nameof(applicationBasePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
return applicationBuilder.UseSetting(WebApplicationConfiguration.ApplicationBaseKey, applicationBasePath);
|
return applicationBuilder.UseSetting(WebApplicationDefaults.ApplicationBaseKey, applicationBasePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IWebApplicationBuilder UseEnvironment(this IWebApplicationBuilder applicationBuilder, string environment)
|
public static IWebApplicationBuilder UseEnvironment(this IWebApplicationBuilder applicationBuilder, string environment)
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
throw new ArgumentNullException(nameof(environment));
|
throw new ArgumentNullException(nameof(environment));
|
||||||
}
|
}
|
||||||
|
|
||||||
return applicationBuilder.UseSetting(WebApplicationConfiguration.EnvironmentKey, environment);
|
return applicationBuilder.UseSetting(WebApplicationDefaults.EnvironmentKey, environment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IWebApplicationBuilder UseWebRoot(this IWebApplicationBuilder applicationBuilder, string webRoot)
|
public static IWebApplicationBuilder UseWebRoot(this IWebApplicationBuilder applicationBuilder, string webRoot)
|
||||||
|
|
@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
throw new ArgumentNullException(nameof(webRoot));
|
throw new ArgumentNullException(nameof(webRoot));
|
||||||
}
|
}
|
||||||
|
|
||||||
return applicationBuilder.UseSetting(WebApplicationConfiguration.WebRootKey, webRoot);
|
return applicationBuilder.UseSetting(WebApplicationDefaults.WebRootKey, webRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IWebApplicationBuilder UseUrls(this IWebApplicationBuilder applicationBuilder, params string[] urls)
|
public static IWebApplicationBuilder UseUrls(this IWebApplicationBuilder applicationBuilder, params string[] urls)
|
||||||
|
|
@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
throw new ArgumentNullException(nameof(urls));
|
throw new ArgumentNullException(nameof(urls));
|
||||||
}
|
}
|
||||||
|
|
||||||
return applicationBuilder.UseSetting(WebApplicationConfiguration.ServerUrlsKey, string.Join(ServerUrlsSeparator, urls));
|
return applicationBuilder.UseSetting(WebApplicationDefaults.ServerUrlsKey, string.Join(ServerUrlsSeparator, urls));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IWebApplicationBuilder UseStartup(this IWebApplicationBuilder applicationBuilder, string startupAssemblyName)
|
public static IWebApplicationBuilder UseStartup(this IWebApplicationBuilder applicationBuilder, string startupAssemblyName)
|
||||||
|
|
@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Hosting
|
||||||
throw new ArgumentNullException(nameof(startupAssemblyName));
|
throw new ArgumentNullException(nameof(startupAssemblyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
return applicationBuilder.UseSetting(WebApplicationConfiguration.ApplicationKey, startupAssemblyName);
|
return applicationBuilder.UseSetting(WebApplicationDefaults.ApplicationKey, startupAssemblyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IWebApplication Start(this IWebApplicationBuilder applicationBuilder, params string[] urls)
|
public static IWebApplication Start(this IWebApplicationBuilder applicationBuilder, params string[] urls)
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,6 @@ namespace Microsoft.AspNet.Hosting
|
||||||
{
|
{
|
||||||
public class WebApplicationConfiguration
|
public class WebApplicationConfiguration
|
||||||
{
|
{
|
||||||
public static readonly string ApplicationKey = "application";
|
|
||||||
public static readonly string DetailedErrorsKey = "detailedErrors";
|
|
||||||
public static readonly string EnvironmentKey = "environment";
|
|
||||||
public static readonly string ServerKey = "server";
|
|
||||||
public static readonly string WebRootKey = "webroot";
|
|
||||||
public static readonly string CaptureStartupErrorsKey = "captureStartupErrors";
|
|
||||||
public static readonly string ServerUrlsKey = "server.urls";
|
|
||||||
public static readonly string ApplicationBaseKey = "applicationBase";
|
|
||||||
|
|
||||||
public static readonly string HostingJsonFile = "hosting.json";
|
|
||||||
public static readonly string EnvironmentVariablesPrefix = "ASPNET_";
|
|
||||||
|
|
||||||
public static IConfiguration GetDefault()
|
public static IConfiguration GetDefault()
|
||||||
{
|
{
|
||||||
return GetDefault(args: null);
|
return GetDefault(args: null);
|
||||||
|
|
@ -26,9 +14,9 @@ namespace Microsoft.AspNet.Hosting
|
||||||
// We are adding all environment variables first and then adding the ASPNET_ ones
|
// We are adding all environment variables first and then adding the ASPNET_ ones
|
||||||
// with the prefix removed to unify with the command line and config file formats
|
// with the prefix removed to unify with the command line and config file formats
|
||||||
var configBuilder = new ConfigurationBuilder()
|
var configBuilder = new ConfigurationBuilder()
|
||||||
.AddJsonFile(HostingJsonFile, optional: true)
|
.AddJsonFile(WebApplicationDefaults.HostingJsonFile, optional: true)
|
||||||
.AddEnvironmentVariables()
|
.AddEnvironmentVariables()
|
||||||
.AddEnvironmentVariables(prefix: EnvironmentVariablesPrefix);
|
.AddEnvironmentVariables(prefix: WebApplicationDefaults.EnvironmentVariablesPrefix);
|
||||||
|
|
||||||
if (args != null)
|
if (args != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue