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

Commit fa02ae8

Browse files
committed
Expose WebHostBuilderContext in UseKestrel #1334
1 parent 6a793c2 commit fa02ae8

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

samples/SampleApp/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public static Task Main(string[] args)
5757
{
5858
factory.AddConsole();
5959
})
60-
.UseKestrel(options =>
6160
{
61+
.UseKestrel((context, options) =>
6262
// Run callbacks on the transport thread
6363
options.ApplicationSchedulingMode = SchedulingMode.Inline;
6464

src/Kestrel/WebHostBuilderKestrelExtensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,31 @@ public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder, Actio
5757
services.Configure(options);
5858
});
5959
}
60+
61+
/// <summary>
62+
/// Specify Kestrel as the server to be used by the web host.
63+
/// </summary>
64+
/// <param name="hostBuilder">
65+
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder to configure.
66+
/// </param>
67+
/// <param name="configureOptions">A callback to configure Kestrel options.</param>
68+
/// <returns>
69+
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder.
70+
/// </returns>
71+
public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder, Action<WebHostBuilderContext, KestrelServerOptions> configureOptions)
72+
{
73+
if (configureOptions == null)
74+
{
75+
throw new ArgumentNullException(nameof(configureOptions));
76+
}
77+
78+
return hostBuilder.UseKestrel().ConfigureServices((context, services) =>
79+
{
80+
services.Configure<KestrelServerOptions>(options =>
81+
{
82+
configureOptions(context, options);
83+
});
84+
});
85+
}
6086
}
6187
}

0 commit comments

Comments
 (0)