Add new ConfigureKestrel extensions #2760

This commit is contained in:
Chris Ross (ASP.NET) 2018-07-27 15:25:18 -07:00
parent c7dd9ff68a
commit 647e7c3266
2 changed files with 36 additions and 3 deletions

View File

@ -24,7 +24,8 @@ namespace Http2SampleApp
factory.SetMinimumLevel(LogLevel.Trace);
factory.AddConsole();
})
.UseKestrel((context, options) =>
.UseKestrel()
.ConfigureKestrel((context, options) =>
{
var basePort = context.Configuration.GetValue<int?>("BASE_PORT") ?? 5000;

View File

@ -50,7 +50,24 @@ namespace Microsoft.AspNetCore.Hosting
/// </returns>
public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder, Action<KestrelServerOptions> options)
{
return hostBuilder.UseKestrel().ConfigureServices(services =>
return hostBuilder.UseKestrel().ConfigureKestrel(options);
}
/// <summary>
/// Configures Kestrel options but does not register an IServer. See <see cref="UseKestrel(IWebHostBuilder)"/>.
/// </summary>
/// <param name="hostBuilder">
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder to configure.
/// </param>
/// <param name="options">
/// A callback to configure Kestrel options.
/// </param>
/// <returns>
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder.
/// </returns>
public static IWebHostBuilder ConfigureKestrel(this IWebHostBuilder hostBuilder, Action<KestrelServerOptions> options)
{
return hostBuilder.ConfigureServices(services =>
{
services.Configure(options);
});
@ -67,13 +84,28 @@ namespace Microsoft.AspNetCore.Hosting
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder.
/// </returns>
public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder, Action<WebHostBuilderContext, KestrelServerOptions> configureOptions)
{
return hostBuilder.UseKestrel().ConfigureKestrel(configureOptions);
}
/// <summary>
/// Configures Kestrel options but does not register an IServer. See <see cref="UseKestrel(IWebHostBuilder)"/>.
/// </summary>
/// <param name="hostBuilder">
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder to configure.
/// </param>
/// <param name="configureOptions">A callback to configure Kestrel options.</param>
/// <returns>
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder.
/// </returns>
public static IWebHostBuilder ConfigureKestrel(this IWebHostBuilder hostBuilder, Action<WebHostBuilderContext, KestrelServerOptions> configureOptions)
{
if (configureOptions == null)
{
throw new ArgumentNullException(nameof(configureOptions));
}
return hostBuilder.UseKestrel().ConfigureServices((context, services) =>
return hostBuilder.ConfigureServices((context, services) =>
{
services.Configure<KestrelServerOptions>(options =>
{