Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions samples/Http2SampleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,17 @@ public class Program
{
public static void Main(string[] args)
{
var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.Build();

if (!ushort.TryParse(configuration["BASE_PORT"], NumberStyles.None, CultureInfo.InvariantCulture, out var basePort))
{
basePort = 5000;
}

var hostBuilder = new WebHostBuilder()
.ConfigureLogging((_, factory) =>
{
// Set logging to the MAX.
factory.SetMinimumLevel(LogLevel.Trace);
factory.AddConsole();
})
.UseKestrel(options =>
.UseKestrel((context, options) =>
{
var basePort = context.Configuration.GetValue<int?>("BASE_PORT") ?? 5000;

// Run callbacks on the transport thread
options.ApplicationSchedulingMode = SchedulingMode.Inline;

Expand Down
13 changes: 3 additions & 10 deletions samples/SampleApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,15 @@ public static Task Main(string[] args)
Console.WriteLine("Unobserved exception: {0}", e.Exception);
};

var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.Build();

if (!ushort.TryParse(configuration["BASE_PORT"], NumberStyles.None, CultureInfo.InvariantCulture, out var basePort))
{
basePort = 5000;
}

var hostBuilder = new WebHostBuilder()
.ConfigureLogging((_, factory) =>
{
factory.AddConsole();
})
.UseKestrel(options =>
.UseKestrel((context, options) =>
{
var basePort = context.Configuration.GetValue<int?>("BASE_PORT") ?? 5000;

// Run callbacks on the transport thread
options.ApplicationSchedulingMode = SchedulingMode.Inline;

Expand Down
26 changes: 26 additions & 0 deletions src/Kestrel/WebHostBuilderKestrelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,31 @@ public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder, Actio
services.Configure(options);
});
}

/// <summary>
/// Specify Kestrel as the server to be used by the web host.
/// </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 UseKestrel(this IWebHostBuilder hostBuilder, Action<WebHostBuilderContext, KestrelServerOptions> configureOptions)
{
if (configureOptions == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this null check be added to the extension above as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

services.Configure does that check.

{
throw new ArgumentNullException(nameof(configureOptions));
}

return hostBuilder.UseKestrel().ConfigureServices((context, services) =>
{
services.Configure<KestrelServerOptions>(options =>
{
configureOptions(context, options);
});
});
}
}
}
4 changes: 2 additions & 2 deletions test/SystemdActivation/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
set -e

cd /publish
systemd-socket-activate -l 8080 -E BASE_PORT=7000 dotnet SampleApp.dll &
systemd-socket-activate -l 8080 -E ASPNETCORE_BASE_PORT=7000 dotnet SampleApp.dll &
socat TCP-LISTEN:8081,fork TCP-CONNECT:127.0.0.1:7000 &
socat TCP-LISTEN:8082,fork TCP-CONNECT:127.0.0.1:7001 &
systemd-socket-activate -l /tmp/activate-kestrel.sock -E BASE_PORT=7100 dotnet SampleApp.dll &
systemd-socket-activate -l /tmp/activate-kestrel.sock -E ASPNETCORE_BASE_PORT=7100 dotnet SampleApp.dll &
socat TCP-LISTEN:8083,fork UNIX-CLIENT:/tmp/activate-kestrel.sock &
socat TCP-LISTEN:8084,fork TCP-CONNECT:127.0.0.1:7100 &
socat TCP-LISTEN:8085,fork TCP-CONNECT:127.0.0.1:7101 &
Expand Down