54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System;
|
|
using Microsoft.AspNetCore.Hosting.Server;
|
|
using Microsoft.AspNetCore.Server.Kestrel;
|
|
using Microsoft.AspNetCore.Server.Kestrel.Internal;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Microsoft.AspNetCore.Hosting
|
|
{
|
|
public static class WebHostBuilderKestrelExtensions
|
|
{
|
|
/// <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>
|
|
/// <returns>
|
|
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder.
|
|
/// </returns>
|
|
public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder)
|
|
{
|
|
return hostBuilder.ConfigureServices(services =>
|
|
{
|
|
services.AddTransient<IConfigureOptions<KestrelServerOptions>, KestrelServerOptionsSetup>();
|
|
services.AddSingleton<IServer, KestrelServer>();
|
|
});
|
|
}
|
|
|
|
/// <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="options">
|
|
/// A callback to configure Kestrel options.
|
|
/// </param>
|
|
/// <returns>
|
|
/// The Microsoft.AspNetCore.Hosting.IWebHostBuilder.
|
|
/// </returns>
|
|
public static IWebHostBuilder UseKestrel(this IWebHostBuilder hostBuilder, Action<KestrelServerOptions> options)
|
|
{
|
|
return hostBuilder.UseKestrel().ConfigureServices(services =>
|
|
{
|
|
services.Configure(options);
|
|
});
|
|
}
|
|
}
|
|
}
|