/
GenericHostBuilderExtensions.cs
46 lines (42 loc) · 2.16 KB
/
GenericHostBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 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;
using Microsoft.AspNetCore;
namespace Microsoft.Extensions.Hosting
{
/// <summary>
/// Extension methods for configuring the <see cref="IHostBuilder" />.
/// </summary>
public static class GenericHostBuilderExtensions
{
/// <summary>
/// Configures a <see cref="IHostBuilder" /> with defaults for hosting a web app.
/// </summary>
/// <remarks>
/// The following defaults are applied to the <see cref="IHostBuilder"/>:
/// <list type="bullet">
/// <item><description>use Kestrel as the web server and configure it using the application's configuration providers</description></item>
/// <item><description>configure <see cref="IWebHostEnvironment.WebRootFileProvider"/> to include static web assets from projects referenced by the entry assembly during development</description></item>
/// <item><description>adds the HostFiltering middleware</description></item>
/// <item><description>adds the ForwardedHeaders middleware if ASPNETCORE_FORWARDEDHEADERS_ENABLED=true,</description></item>
/// <item><description>enable IIS integration</description></item>
/// </list>
/// </remarks>
/// <param name="builder">The <see cref="IHostBuilder" /> instance to configure.</param>
/// <param name="configure">The configure callback</param>
/// <returns>A reference to the <paramref name="builder"/> after the operation has completed.</returns>
public static IHostBuilder ConfigureWebHostDefaults(this IHostBuilder builder, Action<IWebHostBuilder> configure)
{
if (configure is null)
{
throw new ArgumentNullException(nameof(configure));
}
return builder.ConfigureWebHost(webHostBuilder =>
{
WebHost.ConfigureWebDefaults(webHostBuilder);
configure(webHostBuilder);
});
}
}
}