Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
#700 #727 Add environment variables by default and remove UseDefaultH…
Browse files Browse the repository at this point in the history
…ostingConfiguration
  • Loading branch information
JunTaoLuo committed Apr 27, 2016
1 parent 3853d98 commit 1f61593
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 31 deletions.
5 changes: 4 additions & 1 deletion samples/SampleStartups/StartupBlockingOnStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

// Note that this sample will not run. It is only here to illustrate usage patterns.
Expand All @@ -28,8 +29,10 @@ public void Configure(IApplicationBuilder app)
// Entry point for the application.
public static void Main(string[] args)
{
var config = new ConfigurationBuilder().AddCommandLine(args).Build();

var host = new WebHostBuilder()
.UseDefaultHostingConfiguration(args)
.UseConfiguration(config)
.UseStartup<StartupBlockingOnStart>()
.Build();

Expand Down
5 changes: 4 additions & 1 deletion samples/SampleStartups/StartupConfigureAddresses.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

// Note that this sample will not run. It is only here to illustrate usage patterns.
Expand All @@ -27,8 +28,10 @@ public void Configure(IApplicationBuilder app)
// Entry point for the application.
public static void Main(string[] args)
{
var config = new ConfigurationBuilder().AddCommandLine(args).Build();

var host = new WebHostBuilder()
.UseDefaultHostingConfiguration(args)
.UseConfiguration(config)
.UseStartup<StartupConfigureAddresses>()
.UseUrls("http://localhost:5000", "http://localhost:5001")
.Build();
Expand Down
5 changes: 4 additions & 1 deletion samples/SampleStartups/StartupHelloWorld.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

// Note that this sample will not run. It is only here to illustrate usage patterns.
Expand All @@ -27,8 +28,10 @@ public void Configure(IApplicationBuilder app)
// Entry point for the application.
public static void Main(string[] args)
{
var config = new ConfigurationBuilder().AddCommandLine(args).Build();

var host = new WebHostBuilder()
.UseDefaultHostingConfiguration(args)
.UseConfiguration(config)
.UseStartup<StartupHelloWorld>()
.Build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// 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
Expand All @@ -18,8 +17,7 @@ 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);
.AddJsonFile(WebHostDefaults.HostingJsonFile, optional: true);

if (args != null)
{
Expand Down
6 changes: 5 additions & 1 deletion src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public class WebHostBuilder : IWebHostBuilder
private readonly List<Action<IServiceCollection>> _configureServicesDelegates;
private readonly List<Action<ILoggerFactory>> _configureLoggingDelegates;

private IConfiguration _config = new ConfigurationBuilder().AddInMemoryCollection().Build();
private IConfiguration _config = new ConfigurationBuilder()
.AddInMemoryCollection()
.AddEnvironmentVariables(prefix: WebHostDefaults.EnvironmentVariablesPrefix)
.Build();

private ILoggerFactory _loggerFactory;
private WebHostOptions _options;

Expand Down
22 changes: 0 additions & 22 deletions src/Microsoft.AspNetCore.Hosting/WebHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Hosting.Internal;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -15,27 +14,6 @@ public static class WebHostBuilderExtensions
{
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>
/// Use the given configuration settings on the web host.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,9 @@ public void MultipleConfigureLoggingInvokedInOrder()
}

[Fact]
public void DefaultHostingConfigurationDoesNotCaptureStartupErrors()
public void DoesNotCaptureStartupErrorsByDefault()
{
var hostBuilder = new WebHostBuilder()
.UseDefaultHostingConfiguration()
.UseServer(new TestServer())
.UseStartup<StartupBoom>();

Expand Down

0 comments on commit 1f61593

Please sign in to comment.