Skip to content

Commit 5407fb0

Browse files
Address review feedback: Add pragma disables and update to HostBuilder pattern
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
1 parent 8869208 commit 5407fb0

File tree

4 files changed

+154
-107
lines changed

4 files changed

+154
-107
lines changed

src/Hosting/Hosting/src/WebHostBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ namespace Microsoft.AspNetCore.Hosting;
2020
/// <summary>
2121
/// A builder for <see cref="IWebHost"/>
2222
/// </summary>
23+
#pragma warning disable CS0618 // Type or member is obsolete
2324
[Obsolete("TODO: Add Obsolete message")]
25+
#pragma warning restore CS0618 // Type or member is obsolete
2426
public class WebHostBuilder : IWebHostBuilder
2527
{
2628
private readonly HostingEnvironment _hostingEnvironment;
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.IO;
5+
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.Extensions.Hosting;
7+
48
namespace IdentitySample;
59

610
public static class Program
@@ -12,10 +16,14 @@ public static void Main(string[] args)
1216
host.Run();
1317
}
1418

15-
public static IWebHostBuilder CreateHostBuilder(string[] args) =>
16-
new WebHostBuilder()
17-
.UseKestrel()
18-
.UseContentRoot(Directory.GetCurrentDirectory())
19-
.UseIISIntegration()
20-
.UseStartup<Startup>();
19+
public static IHostBuilder CreateHostBuilder(string[] args) =>
20+
new HostBuilder()
21+
.ConfigureWebHost(webHostBuilder =>
22+
{
23+
webHostBuilder
24+
.UseKestrel()
25+
.UseContentRoot(Directory.GetCurrentDirectory())
26+
.UseIISIntegration()
27+
.UseStartup<Startup>();
28+
});
2129
}

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,26 @@ public static int Main(string[] args)
5656
return 12;
5757
case "HangOnStop":
5858
{
59-
var host = new HostBuilder()
60-
.ConfigureWebHost(webHostBuilder =>
61-
{
62-
webHostBuilder
63-
.UseIIS()
64-
.UseStartup<Startup>();
65-
})
59+
#pragma warning disable CS0618 // Type or member is obsolete
60+
var host = new WebHostBuilder()
61+
.UseIIS()
62+
.UseStartup<Startup>()
6663
.Build();
64+
#pragma warning restore CS0618 // Type or member is obsolete
6765
host.Run();
6866

6967
Thread.Sleep(Timeout.Infinite);
7068
}
7169
break;
7270
case "IncreaseShutdownLimit":
7371
{
74-
var host = new HostBuilder()
75-
.ConfigureWebHost(webHostBuilder =>
76-
{
77-
webHostBuilder
78-
.UseIIS()
79-
.UseShutdownTimeout(TimeSpan.FromSeconds(120))
80-
.UseStartup<Startup>();
81-
})
72+
#pragma warning disable CS0618 // Type or member is obsolete
73+
var host = new WebHostBuilder()
74+
.UseIIS()
75+
.UseShutdownTimeout(TimeSpan.FromSeconds(120))
76+
.UseStartup<Startup>()
8277
.Build();
78+
#pragma warning restore CS0618 // Type or member is obsolete
8379

8480
host.Run();
8581
}
@@ -102,15 +98,13 @@ public static int Main(string[] args)
10298
return 0;
10399
case "OverriddenServer":
104100
{
105-
var host = new HostBuilder()
106-
.ConfigureWebHost(webHostBuilder =>
107-
{
108-
webHostBuilder
109-
.UseIIS()
110-
.ConfigureServices(services => services.AddSingleton<IServer, DummyServer>())
111-
.Configure(builder => builder.Run(async context => { await context.Response.WriteAsync("I shouldn't work"); }));
112-
})
113-
.Build();
101+
#pragma warning disable CS0618 // Type or member is obsolete
102+
var host = new WebHostBuilder()
103+
.UseIIS()
104+
.ConfigureServices(services => services.AddSingleton<IServer, DummyServer>())
105+
.Configure(builder => builder.Run(async context => { await context.Response.WriteAsync("I shouldn't work"); }))
106+
.Build();
107+
#pragma warning restore CS0618 // Type or member is obsolete
114108
host.Run();
115109
}
116110
break;
@@ -123,43 +117,39 @@ public static int Main(string[] args)
123117
#if !FORWARDCOMPAT
124118
case "DecreaseRequestLimit":
125119
{
126-
var host = new HostBuilder()
120+
#pragma warning disable CS0618 // Type or member is obsolete
121+
var host = new WebHostBuilder()
127122
.ConfigureLogging((_, factory) =>
128123
{
129124
factory.AddConsole();
130125
factory.AddFilter("Console", level => level >= LogLevel.Information);
131126
})
132-
.ConfigureWebHost(webHostBuilder =>
127+
.UseIIS()
128+
.ConfigureServices(services =>
133129
{
134-
webHostBuilder
135-
.UseIIS()
136-
.ConfigureServices(services =>
137-
{
138-
services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = 2);
139-
})
140-
.UseStartup<Startup>();
130+
services.Configure<IISServerOptions>(options => options.MaxRequestBodySize = 2);
141131
})
132+
.UseStartup<Startup>()
142133
.Build();
134+
#pragma warning restore CS0618 // Type or member is obsolete
143135

144136
host.Run();
145137
break;
146138
}
147139
#endif
148140
case "ThrowInStartup":
149141
{
150-
var host = new HostBuilder()
151-
.ConfigureLogging((_, factory) =>
152-
{
153-
factory.AddConsole();
154-
factory.AddFilter("Console", level => level >= LogLevel.Information);
155-
})
156-
.ConfigureWebHost(webHostBuilder =>
157-
{
158-
webHostBuilder
159-
.UseIIS()
160-
.UseStartup<ThrowingStartup>();
161-
})
162-
.Build();
142+
#pragma warning disable CS0618 // Type or member is obsolete
143+
var host = new WebHostBuilder()
144+
.ConfigureLogging((_, factory) =>
145+
{
146+
factory.AddConsole();
147+
factory.AddFilter("Console", level => level >= LogLevel.Information);
148+
})
149+
.UseIIS()
150+
.UseStartup<ThrowingStartup>()
151+
.Build();
152+
#pragma warning restore CS0618 // Type or member is obsolete
163153

164154
host.Run();
165155
}
@@ -209,21 +199,19 @@ public static int Main(string[] args)
209199

210200
private static int StartServer()
211201
{
212-
var host = new HostBuilder()
202+
#pragma warning disable CS0618 // Type or member is obsolete
203+
var host = new WebHostBuilder()
213204
.ConfigureLogging((_, factory) =>
214205
{
215206
factory.AddConsole();
216207
factory.AddFilter("Console", level => level >= LogLevel.Information);
217208
})
218-
.ConfigureWebHost(webHostBuilder =>
219-
{
220-
webHostBuilder
221-
.UseKestrel()
222-
.UseIIS()
223-
.UseIISIntegration()
224-
.UseStartup<Startup>();
225-
})
209+
.UseKestrel()
210+
.UseIIS()
211+
.UseIISIntegration()
212+
.UseStartup<Startup>()
226213
.Build();
214+
#pragma warning restore CS0618 // Type or member is obsolete
227215

228216
host.Run();
229217
return 0;

0 commit comments

Comments
 (0)