Kestrelhttpserver: Consider adding UseKestrel extension method to IWebHostBuilder

Created on 26 Mar 2016  路  13Comments  路  Source: aspnet/KestrelHttpServer

A comment from @NickCraver here https://github.com/aspnet/IISIntegration/issues/105#issuecomment-201623725. It would be nice if we started to follow this pattern. It would allow servers to expose strongly typed extension methods (similar to our middleware pattern).

3 - Done enhancement

Most helpful comment

@Tratcher I was thinking about that as well. It would be a cleaner way to configure the server settings.

``` C#
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup()
.Build();

host.Run();

You could also configure the server outside of the application making it more portable. It wouldn't take away from configuring things in startup of course but it is cleaner.

``` C#
var host = new WebHostBuilder()
    .UseKestrel(options =>
     {
         options.NoDelay = true;
         options.ThreadCount = 4;
         options.UseHttps(...);
     })
    .UseStartup<StartupHelloWorld>()
    .Build();

host.Run();

All 13 comments

/cc @DamianEdwards @Tratcher @halter73 @lodejard

+1 on this as it does feel very unnatural passing a string to .UseServer()

Do it.

Should there also be an overload that takes some ketrel Options / configureOptions and registers them in DI so they can be injected into the ServerFactory? Most of IKestrelServerInformation would qualify.

@Tratcher I was thinking about that as well. It would be a cleaner way to configure the server settings.

``` C#
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup()
.Build();

host.Run();

You could also configure the server outside of the application making it more portable. It wouldn't take away from configuring things in startup of course but it is cleaner.

``` C#
var host = new WebHostBuilder()
    .UseKestrel(options =>
     {
         options.NoDelay = true;
         options.ThreadCount = 4;
         options.UseHttps(...);
     })
    .UseStartup<StartupHelloWorld>()
    .Build();

host.Run();

/cc @muratg @Eilon

Isn't options.UseKestrelHttps redundant since you are inside the UseKestrel configure block?

@smbecker Fixed

Looks nice to me.

We should also remove these as a result of this:

https://github.com/aspnet/KestrelHttpServer/blob/dev/src/Microsoft.AspNetCore.Server.Kestrel.Https/HttpsApplicationBuilderExtensions.cs

It clears up the fact that these aren't actually pieces of middleware but server configuration.

Putting it optimistically in RC2.

Should this issue be closed yet since the pull request that was merged only included the no-args extension method and didn't include the configure options overload?

You're correct. Leaving open for the options overload.

Created #720 to track configure options overload, and closing this issue.

Was this page helpful?
0 / 5 - 0 ratings