Skip to content

Commit 749289e

Browse files
Complete transformation of all remaining Startup.cs files from WebHostBuilder to HostBuilder
Co-authored-by: BrennanConroy <[email protected]>
1 parent 531bb5f commit 749289e

File tree

10 files changed

+122
-68
lines changed

10 files changed

+122
-68
lines changed

src/Mvc/test/WebSites/ApiExplorerWebSite/Startup.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using ApiExplorerWebSite.Controllers;
55
using Microsoft.AspNetCore.Mvc.Formatters;
66
using Microsoft.AspNetCore.Mvc.Infrastructure;
7+
using Microsoft.Extensions.Hosting;
78

89
namespace ApiExplorerWebSite;
910

@@ -45,17 +46,21 @@ public void Configure(IApplicationBuilder app)
4546

4647
public static void Main(string[] args)
4748
{
48-
var host = CreateWebHostBuilder(args)
49+
using var host = CreateHost(args)
4950
.Build();
5051

5152
host.Run();
5253
}
5354

54-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
55-
new WebHostBuilder()
56-
.UseContentRoot(Directory.GetCurrentDirectory())
57-
.UseKestrel()
58-
.UseIISIntegration()
59-
.UseStartup<Startup>();
55+
public static IHostBuilder CreateHost(string[] args) =>
56+
new HostBuilder()
57+
.ConfigureWebHost(webHostBuilder =>
58+
{
59+
webHostBuilder
60+
.UseContentRoot(Directory.GetCurrentDirectory())
61+
.UseKestrel()
62+
.UseIISIntegration()
63+
.UseStartup<Startup>();
64+
});
6065
}
6166

src/Mvc/test/WebSites/ApplicationModelWebSite/Startup.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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 Microsoft.Extensions.Hosting;
5+
46
namespace ApplicationModelWebSite;
57

68
public class Startup
@@ -34,17 +36,21 @@ public void Configure(IApplicationBuilder app)
3436

3537
public static void Main(string[] args)
3638
{
37-
var host = CreateWebHostBuilder(args)
39+
using var host = CreateHost(args)
3840
.Build();
3941

4042
host.Run();
4143
}
4244

43-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
44-
new WebHostBuilder()
45-
.UseContentRoot(Directory.GetCurrentDirectory())
46-
.UseStartup<Startup>()
47-
.UseKestrel()
48-
.UseIISIntegration();
45+
public static IHostBuilder CreateHost(string[] args) =>
46+
new HostBuilder()
47+
.ConfigureWebHost(webHostBuilder =>
48+
{
49+
webHostBuilder
50+
.UseContentRoot(Directory.GetCurrentDirectory())
51+
.UseStartup<Startup>()
52+
.UseKestrel()
53+
.UseIISIntegration();
54+
});
4955
}
5056

src/Mvc/test/WebSites/ControllersFromServicesWebSite/Startup.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using ControllersFromServicesWebSite.Components;
77
using ControllersFromServicesWebSite.TagHelpers;
88
using Microsoft.AspNetCore.Mvc.ApplicationParts;
9+
using Microsoft.Extensions.Hosting;
910

1011
namespace ControllersFromServicesWebSite;
1112

@@ -61,17 +62,21 @@ public void Configure(IApplicationBuilder app)
6162

6263
public static void Main(string[] args)
6364
{
64-
var host = CreateWebHostBuilder(args)
65+
using var host = CreateHost(args)
6566
.Build();
6667

6768
host.Run();
6869
}
6970

70-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
71-
new WebHostBuilder()
72-
.UseContentRoot(Directory.GetCurrentDirectory())
73-
.UseStartup<Startup>()
74-
.UseKestrel()
75-
.UseIISIntegration();
71+
public static IHostBuilder CreateHost(string[] args) =>
72+
new HostBuilder()
73+
.ConfigureWebHost(webHostBuilder =>
74+
{
75+
webHostBuilder
76+
.UseContentRoot(Directory.GetCurrentDirectory())
77+
.UseStartup<Startup>()
78+
.UseKestrel()
79+
.UseIISIntegration();
80+
});
7681
}
7782

src/Mvc/test/WebSites/ErrorPageMiddlewareWebSite/Startup.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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 Microsoft.Extensions.Hosting;
5+
46
namespace ErrorPageMiddlewareWebSite;
57

68
public class Startup
@@ -24,17 +26,21 @@ public void Configure(IApplicationBuilder app)
2426

2527
public static void Main(string[] args)
2628
{
27-
var host = CreateWebHostBuilder(args)
29+
using var host = CreateHost(args)
2830
.Build();
2931

3032
host.Run();
3133
}
3234

33-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
34-
new WebHostBuilder()
35-
.UseContentRoot(Directory.GetCurrentDirectory())
36-
.UseStartup<Startup>()
37-
.UseKestrel()
38-
.UseIISIntegration();
35+
public static IHostBuilder CreateHost(string[] args) =>
36+
new HostBuilder()
37+
.ConfigureWebHost(webHostBuilder =>
38+
{
39+
webHostBuilder
40+
.UseContentRoot(Directory.GetCurrentDirectory())
41+
.UseStartup<Startup>()
42+
.UseKestrel()
43+
.UseIISIntegration();
44+
});
3945
}
4046

src/Mvc/test/WebSites/HtmlGenerationWebSite/Startup.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.AspNetCore.Mvc.TagHelpers;
66
using Microsoft.Extensions.Caching.Memory;
7+
using Microsoft.Extensions.Hosting;
78

89
namespace HtmlGenerationWebSite;
910

@@ -48,18 +49,22 @@ public virtual void Configure(IApplicationBuilder app)
4849

4950
public static void Main(string[] args)
5051
{
51-
var host = CreateWebHostBuilder(args)
52+
using var host = CreateHost(args)
5253
.Build();
5354

5455
host.Run();
5556
}
5657

57-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
58-
new WebHostBuilder()
59-
.UseContentRoot(Directory.GetCurrentDirectory())
60-
.UseStartup<Startup>()
61-
.UseKestrel()
62-
.UseIISIntegration();
58+
public static IHostBuilder CreateHost(string[] args) =>
59+
new HostBuilder()
60+
.ConfigureWebHost(webHostBuilder =>
61+
{
62+
webHostBuilder
63+
.UseContentRoot(Directory.GetCurrentDirectory())
64+
.UseStartup<Startup>()
65+
.UseKestrel()
66+
.UseIISIntegration();
67+
});
6368

6469
protected virtual void ConfigureMvcOptions(MvcOptions options)
6570
{

src/Mvc/test/WebSites/HtmlGenerationWebSite/StartupWithCultureReplace.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Globalization;
5+
using Microsoft.Extensions.Hosting;
56

67
namespace HtmlGenerationWebSite;
78

@@ -31,10 +32,14 @@ public void Configure(IApplicationBuilder app)
3132
Startup.Configure(app);
3233
}
3334

34-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
35-
new WebHostBuilder()
36-
.UseContentRoot(Directory.GetCurrentDirectory())
37-
.UseStartup<StartupWithCultureReplace>()
38-
.UseKestrel()
39-
.UseIISIntegration();
35+
public static IHostBuilder CreateHost(string[] args) =>
36+
new HostBuilder()
37+
.ConfigureWebHost(webHostBuilder =>
38+
{
39+
webHostBuilder
40+
.UseContentRoot(Directory.GetCurrentDirectory())
41+
.UseStartup<StartupWithCultureReplace>()
42+
.UseKestrel()
43+
.UseIISIntegration();
44+
});
4045
}

src/Mvc/test/WebSites/RazorBuildWebSite/Startup.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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 Microsoft.Extensions.Hosting;
5+
46
namespace RazorBuildWebSite;
57

68
public class Startup
@@ -25,10 +27,14 @@ public void Configure(IApplicationBuilder app)
2527
});
2628
}
2729

28-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
29-
new WebHostBuilder()
30-
.UseContentRoot(Directory.GetCurrentDirectory())
31-
.UseStartup<Startup>()
32-
.UseKestrel()
33-
.UseIISIntegration();
30+
public static IHostBuilder CreateHost(string[] args) =>
31+
new HostBuilder()
32+
.ConfigureWebHost(webHostBuilder =>
33+
{
34+
webHostBuilder
35+
.UseContentRoot(Directory.GetCurrentDirectory())
36+
.UseStartup<Startup>()
37+
.UseKestrel()
38+
.UseIISIntegration();
39+
});
3440
}

src/Mvc/test/WebSites/RazorBuildWebSite/StartupWithHostingStartup.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.AspNetCore.Mvc.ApplicationParts;
5+
using Microsoft.Extensions.Hosting;
56

67
namespace RazorBuildWebSite;
78

@@ -34,17 +35,21 @@ public void Configure(IApplicationBuilder app)
3435

3536
public static void Main(string[] args)
3637
{
37-
var host = CreateWebHostBuilder(args)
38+
using var host = CreateHost(args)
3839
.Build();
3940

4041
host.Run();
4142
}
4243

43-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
44-
new WebHostBuilder()
45-
.UseContentRoot(Directory.GetCurrentDirectory())
46-
.UseStartup<Startup>()
47-
.UseKestrel();
44+
public static IHostBuilder CreateHost(string[] args) =>
45+
new HostBuilder()
46+
.ConfigureWebHost(webHostBuilder =>
47+
{
48+
webHostBuilder
49+
.UseContentRoot(Directory.GetCurrentDirectory())
50+
.UseStartup<Startup>()
51+
.UseKestrel();
52+
});
4853

4954
private class MockMvcBuilder : IMvcBuilder
5055
{

src/Mvc/test/WebSites/TagHelpersWebSite/Startup.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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 Microsoft.Extensions.Hosting;
5+
46
namespace TagHelpersWebSite;
57

68
public class Startup
@@ -23,18 +25,22 @@ public void Configure(IApplicationBuilder app)
2325

2426
public static void Main(string[] args)
2527
{
26-
var host = CreateWebHostBuilder(args)
28+
using var host = CreateHost(args)
2729
.Build();
2830

2931
host.Run();
3032
}
3133

32-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
33-
new WebHostBuilder()
34-
.UseContentRoot(Directory.GetCurrentDirectory())
35-
.UseStaticWebAssets()
36-
.UseStartup<Startup>()
37-
.UseKestrel()
38-
.UseIISIntegration();
34+
public static IHostBuilder CreateHost(string[] args) =>
35+
new HostBuilder()
36+
.ConfigureWebHost(webHostBuilder =>
37+
{
38+
webHostBuilder
39+
.UseContentRoot(Directory.GetCurrentDirectory())
40+
.UseStaticWebAssets()
41+
.UseStartup<Startup>()
42+
.UseKestrel()
43+
.UseIISIntegration();
44+
});
3945
}
4046

src/Mvc/test/WebSites/XmlFormattersWebSite/Startup.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.AspNetCore.Mvc.Formatters;
6+
using Microsoft.Extensions.Hosting;
67
using Microsoft.Net.Http.Headers;
78

89
namespace XmlFormattersWebSite;
@@ -109,17 +110,21 @@ public void Configure(IApplicationBuilder app)
109110

110111
public static void Main(string[] args)
111112
{
112-
var host = CreateWebHostBuilder(args)
113+
using var host = CreateHost(args)
113114
.Build();
114115

115116
host.Run();
116117
}
117118

118-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
119-
new WebHostBuilder()
120-
.UseContentRoot(Directory.GetCurrentDirectory())
121-
.UseStartup<Startup>()
122-
.UseKestrel()
123-
.UseIISIntegration();
119+
public static IHostBuilder CreateHost(string[] args) =>
120+
new HostBuilder()
121+
.ConfigureWebHost(webHostBuilder =>
122+
{
123+
webHostBuilder
124+
.UseContentRoot(Directory.GetCurrentDirectory())
125+
.UseStartup<Startup>()
126+
.UseKestrel()
127+
.UseIISIntegration();
128+
});
124129
}
125130

0 commit comments

Comments
 (0)