diff --git a/build/dependencies.props b/build/dependencies.props
index 39b8dbdf02..ee4e17013b 100644
--- a/build/dependencies.props
+++ b/build/dependencies.props
@@ -3,31 +3,34 @@
$(MSBuildAllProjects);$(MSBuildThisFileFullPath)
- 3.0.0-build-20181114.5
- 3.0.0-alpha1-10742
- 3.0.0-alpha1-10742
- 3.0.0-alpha1-10742
- 3.0.0-alpha1-10742
- 3.0.0-alpha1-10742
- 3.0.0-alpha1-10742
- 3.0.0-alpha1-10742
- 3.0.0-alpha1-10742
- 3.0.0-alpha1-10742
- 0.7.0-alpha1-10742
- 3.0.0-alpha1-10742
- 3.0.0-alpha1-10742
- 3.0.0-alpha1-10742
- 3.0.0-preview-181113-11
- 3.0.0-preview-181113-11
- 3.0.0-preview-181113-11
- 3.0.0-preview-181113-11
- 3.0.0-preview-181113-11
- 3.0.0-preview-181113-11
- 3.0.0-preview-181113-11
- 3.0.0-preview-181113-11
- 3.0.0-preview-181113-11
- 3.0.0-preview-181113-11
- 3.0.0-preview1-26907-05
+ 3.0.0-alpha1-20181004.7
+ 3.0.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 0.7.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 3.0.0-alpha1-10733
+ 3.0.0-preview-181108-06
+ 3.0.0-preview-181108-06
+ 3.0.0-preview-181108-06
+ 3.0.0-preview-181108-06
+ 3.0.0-preview-181108-06
+ 3.0.0-preview-181108-06
+ 3.0.0-preview-181108-06
+ 3.0.0-preview-181108-06
+ 3.0.0-preview-181108-06
+ 3.0.0-preview-181108-06
+ 3.0.0-alpha1-10733
+ 2.0.9
+ 2.1.3
+ 2.2.0-rtm-27105-02
15.6.1
4.10.0
2.0.3
diff --git a/samples/SampleApp/Program.cs b/samples/SampleApp/Program.cs
index b5eb900273..1d95226e6c 100644
--- a/samples/SampleApp/Program.cs
+++ b/samples/SampleApp/Program.cs
@@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
namespace SampleApp
{
@@ -23,6 +25,8 @@ namespace SampleApp
CustomApplicationBuilder();
StartupClass(args);
+
+ HostBuilderWithWebHost(args);
}
private static void HelloWorld()
@@ -90,5 +94,21 @@ namespace SampleApp
host.Run();
}
}
+
+ private static void HostBuilderWithWebHost(string[] args)
+ {
+ var host = new HostBuilder()
+ .ConfigureAppConfiguration(config =>
+ {
+ config.AddCommandLine(args);
+ })
+ .ConfigureWebHostDefaults(builder =>
+ {
+ builder.UseStartup();
+ })
+ .Build();
+
+ host.Run();
+ }
}
}
diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj
index 19586777f2..64625f5583 100644
--- a/samples/SampleApp/SampleApp.csproj
+++ b/samples/SampleApp/SampleApp.csproj
@@ -1,4 +1,4 @@
-
+
netcoreapp3.0
@@ -11,6 +11,7 @@
+
diff --git a/src/Microsoft.AspNetCore/GenericHostBuilderExtensions.cs b/src/Microsoft.AspNetCore/GenericHostBuilderExtensions.cs
new file mode 100644
index 0000000000..80d0074e40
--- /dev/null
+++ b/src/Microsoft.AspNetCore/GenericHostBuilderExtensions.cs
@@ -0,0 +1,33 @@
+using System;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore;
+
+namespace Microsoft.Extensions.Hosting
+{
+ ///
+ /// Extension methods for configuring the IWebHostBuilder.
+ ///
+ public static class GenericHostBuilderExtensions
+ {
+ ///
+ /// Initializes a new instance of the class with pre-configured defaults.
+ ///
+ ///
+ /// The following defaults are applied to the :
+ /// use Kestrel as the web server and configure it using the application's configuration providers,
+ /// and enable IIS integration.
+ ///
+ /// The instance to configure
+ /// The configure callback
+ ///
+ public static IHostBuilder ConfigureWebHostDefaults(this IHostBuilder builder, Action configure)
+ {
+ return builder.ConfigureWebHost(webHostBuilder =>
+ {
+ WebHost.ConfigureWebDefaults(webHostBuilder);
+
+ configure(webHostBuilder);
+ });
+ }
+ }
+}
diff --git a/src/Microsoft.AspNetCore/WebHost.cs b/src/Microsoft.AspNetCore/WebHost.cs
index 10726c8356..fd9cadfcb8 100644
--- a/src/Microsoft.AspNetCore/WebHost.cs
+++ b/src/Microsoft.AspNetCore/WebHost.cs
@@ -158,69 +158,75 @@ namespace Microsoft.AspNetCore
builder.UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build());
}
- builder.UseKestrel((builderContext, options) =>
- {
- options.Configure(builderContext.Configuration.GetSection("Kestrel"));
- })
- .ConfigureAppConfiguration((hostingContext, config) =>
- {
- var env = hostingContext.HostingEnvironment;
+ builder.ConfigureAppConfiguration((hostingContext, config) =>
+ {
+ var env = hostingContext.HostingEnvironment;
- config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
- .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
+ config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
+ .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
- if (env.IsDevelopment())
+ if (env.IsDevelopment())
+ {
+ var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
+ if (appAssembly != null)
{
- var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
- if (appAssembly != null)
- {
- config.AddUserSecrets(appAssembly, optional: true);
- }
+ config.AddUserSecrets(appAssembly, optional: true);
}
+ }
- config.AddEnvironmentVariables();
+ config.AddEnvironmentVariables();
- if (args != null)
- {
- config.AddCommandLine(args);
- }
- })
- .ConfigureLogging((hostingContext, logging) =>
+ if (args != null)
{
- logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
- logging.AddConsole();
- logging.AddDebug();
- logging.AddEventSourceLogger();
- })
- .ConfigureServices((hostingContext, services) =>
- {
- // Fallback
- services.PostConfigure(options =>
- {
- if (options.AllowedHosts == null || options.AllowedHosts.Count == 0)
- {
- // "AllowedHosts": "localhost;127.0.0.1;[::1]"
- var hosts = hostingContext.Configuration["AllowedHosts"]?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
- // Fall back to "*" to disable.
- options.AllowedHosts = (hosts?.Length > 0 ? hosts : new[] { "*" });
- }
- });
- // Change notification
- services.AddSingleton>(
- new ConfigurationChangeTokenSource(hostingContext.Configuration));
+ config.AddCommandLine(args);
+ }
+ })
+ .ConfigureLogging((hostingContext, logging) =>
+ {
+ logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
+ logging.AddConsole();
+ logging.AddDebug();
+ logging.AddEventSourceLogger();
+ }).
+ UseDefaultServiceProvider((context, options) =>
+ {
+ options.ValidateScopes = context.HostingEnvironment.IsDevelopment();
+ });
- services.AddTransient();
- })
- .UseIIS()
- .UseIISIntegration()
- .UseDefaultServiceProvider((context, options) =>
- {
- options.ValidateScopes = context.HostingEnvironment.IsDevelopment();
- });
+ ConfigureWebDefaults(builder);
return builder;
}
+ internal static void ConfigureWebDefaults(IWebHostBuilder builder)
+ {
+ builder.UseKestrel((builderContext, options) =>
+ {
+ options.Configure(builderContext.Configuration.GetSection("Kestrel"));
+ })
+ .ConfigureServices((hostingContext, services) =>
+ {
+ // Fallback
+ services.PostConfigure(options =>
+ {
+ if (options.AllowedHosts == null || options.AllowedHosts.Count == 0)
+ {
+ // "AllowedHosts": "localhost;127.0.0.1;[::1]"
+ var hosts = hostingContext.Configuration["AllowedHosts"]?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
+ // Fall back to "*" to disable.
+ options.AllowedHosts = (hosts?.Length > 0 ? hosts : new[] { "*" });
+ }
+ });
+ // Change notification
+ services.AddSingleton>(
+ new ConfigurationChangeTokenSource(hostingContext.Configuration));
+
+ services.AddTransient();
+ })
+ .UseIIS()
+ .UseIISIntegration();
+ }
+
///
/// Initializes a new instance of the class with pre-configured defaults using typed Startup.
///