Skip to content

Commit 64b5ea9

Browse files
authored
[HttpSys] Move to GenericHost (#24285)
1 parent b094ecd commit 64b5ea9

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/Servers/HttpSys/samples/HotAddSample/Startup.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
2+
using System.Threading.Tasks;
23
using Microsoft.AspNetCore.Builder;
34
using Microsoft.AspNetCore.Hosting;
45
using Microsoft.AspNetCore.Http;
56
using Microsoft.AspNetCore.Server.HttpSys;
67
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Hosting;
79
using Microsoft.Extensions.Logging;
810

911
namespace HotAddSample
@@ -96,15 +98,19 @@ public void Configure(IApplicationBuilder app)
9698
});
9799
}
98100

99-
public static void Main(string[] args)
101+
public static Task Main(string[] args)
100102
{
101-
var host = new WebHostBuilder()
103+
var host = new HostBuilder()
104+
.ConfigureWebHost(webHostBuilder =>
105+
{
106+
webHostBuilder
107+
.UseStartup<Startup>()
108+
.UseHttpSys();
109+
})
102110
.ConfigureLogging(factory => factory.AddConsole())
103-
.UseStartup<Startup>()
104-
.UseHttpSys()
105111
.Build();
106112

107-
host.Run();
113+
return host.RunAsync();
108114
}
109115
}
110116
}

src/Servers/HttpSys/test/FunctionalTests/Utilities.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.AspNetCore.Http;
1414
using Microsoft.AspNetCore.Testing;
1515
using Microsoft.Extensions.DependencyInjection;
16+
using Microsoft.Extensions.Hosting;
1617
using Microsoft.Extensions.Logging;
1718
using Microsoft.Extensions.Options;
1819

@@ -66,7 +67,7 @@ internal static IServer CreateHttpAuthServer(AuthenticationSchemes authType, boo
6667
}, app);
6768
}
6869

69-
internal static IWebHost CreateDynamicHost(AuthenticationSchemes authType, bool allowAnonymous, out string root, RequestDelegate app)
70+
internal static IHost CreateDynamicHost(AuthenticationSchemes authType, bool allowAnonymous, out string root, RequestDelegate app)
7071
{
7172
return CreateDynamicHost(string.Empty, out root, out var baseAddress, options =>
7273
{
@@ -75,22 +76,26 @@ internal static IWebHost CreateDynamicHost(AuthenticationSchemes authType, bool
7576
}, app);
7677
}
7778

78-
internal static IWebHost CreateDynamicHost(out string baseAddress, Action<HttpSysOptions> configureOptions, RequestDelegate app)
79+
internal static IHost CreateDynamicHost(out string baseAddress, Action<HttpSysOptions> configureOptions, RequestDelegate app)
7980
{
8081
return CreateDynamicHost(string.Empty, out var root, out baseAddress, configureOptions, app);
8182
}
8283

83-
internal static IWebHost CreateDynamicHost(string basePath, out string root, out string baseAddress, Action<HttpSysOptions> configureOptions, RequestDelegate app)
84+
internal static IHost CreateDynamicHost(string basePath, out string root, out string baseAddress, Action<HttpSysOptions> configureOptions, RequestDelegate app)
8485
{
8586
var prefix = UrlPrefix.Create("http", "localhost", "0", basePath);
8687

87-
var builder = new WebHostBuilder()
88-
.UseHttpSys(options =>
88+
var builder = new HostBuilder()
89+
.ConfigureWebHost(webHostBuilder =>
8990
{
90-
options.UrlPrefixes.Add(prefix);
91-
configureOptions(options);
92-
})
93-
.Configure(appBuilder => appBuilder.Run(app));
91+
webHostBuilder
92+
.UseHttpSys(options =>
93+
{
94+
options.UrlPrefixes.Add(prefix);
95+
configureOptions(options);
96+
})
97+
.Configure(appBuilder => appBuilder.Run(app));
98+
});
9499

95100
var host = builder.Build();
96101

0 commit comments

Comments
 (0)