This commit is contained in:
parent
c3d8a00c11
commit
e505ecbc21
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
// Note that this sample will not run. It is only here to illustrate usage patterns.
|
// Note that this sample will not run. It is only here to illustrate usage patterns.
|
||||||
|
|
@ -28,8 +29,10 @@ namespace SampleStartups
|
||||||
// Entry point for the application.
|
// Entry point for the application.
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
var config = new ConfigurationBuilder().AddCommandLine(args).Build();
|
||||||
|
|
||||||
var host = new WebHostBuilder()
|
var host = new WebHostBuilder()
|
||||||
.UseDefaultHostingConfiguration(args)
|
.UseConfiguration(config)
|
||||||
.UseStartup<StartupBlockingOnStart>()
|
.UseStartup<StartupBlockingOnStart>()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
// Note that this sample will not run. It is only here to illustrate usage patterns.
|
// Note that this sample will not run. It is only here to illustrate usage patterns.
|
||||||
|
|
@ -27,8 +28,10 @@ namespace SampleStartups
|
||||||
// Entry point for the application.
|
// Entry point for the application.
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
var config = new ConfigurationBuilder().AddCommandLine(args).Build();
|
||||||
|
|
||||||
var host = new WebHostBuilder()
|
var host = new WebHostBuilder()
|
||||||
.UseDefaultHostingConfiguration(args)
|
.UseConfiguration(config)
|
||||||
.UseStartup<StartupConfigureAddresses>()
|
.UseStartup<StartupConfigureAddresses>()
|
||||||
.UseUrls("http://localhost:5000", "http://localhost:5001")
|
.UseUrls("http://localhost:5000", "http://localhost:5001")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,9 @@ namespace SampleStartups
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
_host = new WebHostBuilder()
|
_host = new WebHostBuilder()
|
||||||
.UseStartup<StartupExternallyControlled>()
|
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
|
||||||
.Start(_urls.ToArray());
|
.UseStartup<StartupExternallyControlled>()
|
||||||
|
.Start(_urls.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
|
@ -13,7 +14,14 @@ namespace SampleStartups
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
var config = new ConfigurationBuilder()
|
||||||
|
.AddCommandLine(args)
|
||||||
|
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
|
||||||
|
.AddJsonFile("hosting.json", optional: true)
|
||||||
|
.Build();
|
||||||
|
|
||||||
var host = new WebHostBuilder()
|
var host = new WebHostBuilder()
|
||||||
|
.UseConfiguration(config) // Default set of configurations to use, may be subsequently overridden
|
||||||
.UseServer("Microsoft.AspNetCore.Server.Kestrel") // Set the server manually
|
.UseServer("Microsoft.AspNetCore.Server.Kestrel") // Set the server manually
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory()) // Override the content root with the current directory
|
.UseContentRoot(Directory.GetCurrentDirectory()) // Override the content root with the current directory
|
||||||
.UseUrls("http://*:1000", "https://*:902")
|
.UseUrls("http://*:1000", "https://*:902")
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace SampleStartups
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var host = new WebHostBuilder()
|
var host = new WebHostBuilder()
|
||||||
.UseDefaultHostingConfiguration(args)
|
.UseServer("Microsoft.AspNetCore.Server.Kestrel")
|
||||||
.UseStartup<StartupHelloWorld>()
|
.UseStartup<StartupHelloWorld>()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
{
|
{
|
||||||
"version": "1.0.0-*",
|
"version": "1.0.0-*",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNetCore.Hosting": "1.0.0-*"
|
"Microsoft.AspNetCore.Hosting": "1.0.0-*",
|
||||||
|
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-*",
|
||||||
|
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*",
|
||||||
|
"Microsoft.Extensions.Configuration.Json": "1.0.0-*"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net451": {},
|
"net451": {},
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,5 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
public static readonly string CaptureStartupErrorsKey = "captureStartupErrors";
|
public static readonly string CaptureStartupErrorsKey = "captureStartupErrors";
|
||||||
public static readonly string ServerUrlsKey = "server.urls";
|
public static readonly string ServerUrlsKey = "server.urls";
|
||||||
public static readonly string ContentRootKey = "contentRoot";
|
public static readonly string ContentRootKey = "contentRoot";
|
||||||
|
|
||||||
public static readonly string HostingJsonFile = "hosting.json";
|
|
||||||
public static readonly string EnvironmentVariablesPrefix = "ASPNETCORE_";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,11 @@ namespace Microsoft.AspNetCore.Hosting.Internal
|
||||||
{
|
{
|
||||||
hostingEnvironment.WebRootFileProvider = new NullFileProvider();
|
hostingEnvironment.WebRootFileProvider = new NullFileProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
var environmentName = options.Environment;
|
hostingEnvironment.EnvironmentName =
|
||||||
hostingEnvironment.EnvironmentName = environmentName ?? hostingEnvironment.EnvironmentName;
|
options.Environment ??
|
||||||
|
Environment.GetEnvironmentVariable($"ASPNETCORE_{WebHostDefaults.EnvironmentKey}") ??
|
||||||
|
hostingEnvironment.EnvironmentName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Hosting.Internal
|
|
||||||
{
|
|
||||||
public class WebHostConfiguration
|
|
||||||
{
|
|
||||||
public static IConfiguration GetDefault()
|
|
||||||
{
|
|
||||||
return GetDefault(args: null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IConfiguration GetDefault(string[] args)
|
|
||||||
{
|
|
||||||
// Setup the default locations for finding hosting configuration options
|
|
||||||
// hosting.json, ASPNETCORE_ prefixed env variables and command line arguments
|
|
||||||
var configBuilder = new ConfigurationBuilder()
|
|
||||||
.AddJsonFile(WebHostDefaults.HostingJsonFile, optional: true)
|
|
||||||
.AddEnvironmentVariables(prefix: WebHostDefaults.EnvironmentVariablesPrefix);
|
|
||||||
|
|
||||||
if (args != null)
|
|
||||||
{
|
|
||||||
configBuilder.AddCommandLine(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
return configBuilder.Build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Hosting.Internal;
|
|
||||||
using Microsoft.AspNetCore.Hosting.Server;
|
using Microsoft.AspNetCore.Hosting.Server;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -15,27 +14,6 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
{
|
{
|
||||||
private static readonly string ServerUrlsSeparator = ";";
|
private static readonly string ServerUrlsSeparator = ";";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Use the default hosting configuration settings on the web host.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="hostBuilder">The <see cref="IWebHostBuilder"/> to configure.</param>
|
|
||||||
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
|
|
||||||
public static IWebHostBuilder UseDefaultHostingConfiguration(this IWebHostBuilder hostBuilder)
|
|
||||||
{
|
|
||||||
return hostBuilder.UseDefaultHostingConfiguration(args: null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Use the default hosting configuration settings on the web host and allow for override by command line arguments.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="hostBuilder">The <see cref="IWebHostBuilder"/> to configure.</param>
|
|
||||||
/// <param name="args">The command line arguments used to override default settings.</param>
|
|
||||||
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
|
|
||||||
public static IWebHostBuilder UseDefaultHostingConfiguration(this IWebHostBuilder hostBuilder, string[] args)
|
|
||||||
{
|
|
||||||
return hostBuilder.UseConfiguration(WebHostConfiguration.GetDefault(args));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use the given configuration settings on the web host.
|
/// Use the given configuration settings on the web host.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,6 @@
|
||||||
"Microsoft.Extensions.FileProviders.Physical": "1.0.0-*",
|
"Microsoft.Extensions.FileProviders.Physical": "1.0.0-*",
|
||||||
"Microsoft.Extensions.Options": "1.0.0-*",
|
"Microsoft.Extensions.Options": "1.0.0-*",
|
||||||
"Microsoft.Extensions.Configuration": "1.0.0-*",
|
"Microsoft.Extensions.Configuration": "1.0.0-*",
|
||||||
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-*",
|
|
||||||
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*",
|
|
||||||
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
|
|
||||||
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
|
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
|
||||||
"Microsoft.Extensions.Logging": "1.0.0-*",
|
"Microsoft.Extensions.Logging": "1.0.0-*",
|
||||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
|
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
|
||||||
|
|
|
||||||
|
|
@ -190,10 +190,9 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DefaultHostingConfigurationDoesNotCaptureStartupErrors()
|
public void DoNotCaptureStartupErrorsByDefault()
|
||||||
{
|
{
|
||||||
var hostBuilder = new WebHostBuilder()
|
var hostBuilder = new WebHostBuilder()
|
||||||
.UseDefaultHostingConfiguration()
|
|
||||||
.UseServer(new TestServer())
|
.UseServer(new TestServer())
|
||||||
.UseStartup<StartupBoom>();
|
.UseStartup<StartupBoom>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,6 @@ namespace Microsoft.AspNetCore.Hosting.Tests
|
||||||
{
|
{
|
||||||
public class WebHostConfigurationTests
|
public class WebHostConfigurationTests
|
||||||
{
|
{
|
||||||
[Fact]
|
|
||||||
public void DefaultDoesNotCaptureStartupErrors()
|
|
||||||
{
|
|
||||||
var config = new WebHostOptions(WebHostConfiguration.GetDefault());
|
|
||||||
|
|
||||||
Assert.False(config.CaptureStartupErrors);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ReadsParametersCorrectly()
|
public void ReadsParametersCorrectly()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue