Skip to content

Commit 990e639

Browse files
authored
[MusicStore] Move to GenericHost (#24284)
1 parent 3ea1fc7 commit 990e639

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed
Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,78 @@
11
using System;
22
using System.IO;
3+
using System.Threading.Tasks;
34
using Microsoft.AspNetCore.Hosting;
45
using Microsoft.AspNetCore.Server.HttpSys;
56
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.Hosting;
68
using Microsoft.Extensions.Logging;
79

810
namespace MusicStore
911
{
1012
public static class Program
1113
{
12-
public static void Main(string[] args)
14+
public static Task Main(string[] args)
1315
{
1416
var config = new ConfigurationBuilder()
1517
.AddCommandLine(args)
1618
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
1719
.Build();
1820

19-
var builder = new WebHostBuilder()
20-
.UseConfiguration(config)
21-
.UseIISIntegration()
22-
.UseStartup("MusicStore")
23-
.UseDefaultServiceProvider((context, options) => {
24-
options.ValidateScopes = true;
25-
});
21+
var builder = new HostBuilder()
22+
.ConfigureWebHost(webHostBuilder =>
23+
{
24+
webHostBuilder
25+
.UseConfiguration(config)
26+
.UseIISIntegration()
27+
.UseStartup("MusicStore");
2628

27-
var environment = builder.GetSetting("environment") ??
29+
var environment = webHostBuilder.GetSetting("environment") ??
2830
Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
2931

30-
if (string.Equals(builder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal))
31-
{
32-
if (string.Equals(environment, "NtlmAuthentication", System.StringComparison.Ordinal))
33-
{
34-
// Set up NTLM authentication for WebListener like below.
35-
// For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or
36-
// modify the applicationHost.config to enable NTLM.
37-
builder.UseHttpSys(options =>
32+
if (string.Equals(webHostBuilder.GetSetting("server"), "Microsoft.AspNetCore.Server.HttpSys", System.StringComparison.Ordinal))
3833
{
39-
options.Authentication.Schemes = AuthenticationSchemes.NTLM;
40-
options.Authentication.AllowAnonymous = false;
41-
});
42-
}
43-
else
44-
{
45-
builder.UseHttpSys();
46-
}
47-
}
48-
else
49-
{
50-
builder.UseKestrel();
51-
}
34+
if (string.Equals(environment, "NtlmAuthentication", System.StringComparison.Ordinal))
35+
{
36+
// Set up NTLM authentication for WebListener like below.
37+
// For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or
38+
// modify the applicationHost.config to enable NTLM.
39+
webHostBuilder.UseHttpSys(options =>
40+
{
41+
options.Authentication.Schemes = AuthenticationSchemes.NTLM;
42+
options.Authentication.AllowAnonymous = false;
43+
});
44+
}
45+
else
46+
{
47+
webHostBuilder.UseHttpSys();
48+
}
49+
}
50+
else
51+
{
52+
webHostBuilder.UseKestrel();
53+
}
5254

53-
// In Proc
54-
builder.UseIIS();
55+
// In Proc
56+
webHostBuilder.UseIIS();
5557

56-
builder.ConfigureLogging(factory =>
57-
{
58-
factory.AddConsole();
58+
webHostBuilder.ConfigureLogging(factory =>
59+
{
60+
factory.AddConsole();
5961

60-
var logLevel = string.Equals(environment, "Development", StringComparison.Ordinal) ? LogLevel.Information : LogLevel.Warning;
61-
factory.SetMinimumLevel(logLevel);
62+
var logLevel = string.Equals(environment, "Development", StringComparison.Ordinal) ? LogLevel.Information : LogLevel.Warning;
63+
factory.SetMinimumLevel(logLevel);
6264

63-
// Turn off Info logging for EF commands
64-
factory.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning);
65-
});
65+
// Turn off Info logging for EF commands
66+
factory.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning);
67+
});
68+
})
69+
.UseDefaultServiceProvider((context, options) => {
70+
options.ValidateScopes = true;
71+
});
6672

6773
var host = builder.Build();
6874

69-
host.Run();
75+
return host.RunAsync();
7076
}
7177
}
7278
}

0 commit comments

Comments
 (0)