Skip to content

Commit 531bb5f

Browse files
Transform Program.cs files and benchmark apps from WebHostBuilder to HostBuilder
Co-authored-by: BrennanConroy <[email protected]>
1 parent 23e48c6 commit 531bb5f

File tree

10 files changed

+130
-72
lines changed

10 files changed

+130
-72
lines changed

src/Mvc/perf/benchmarkapps/BasicViews/Startup.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#endif
99
using Microsoft.AspNetCore.Builder;
1010
using Microsoft.AspNetCore.Hosting;
11+
using Microsoft.Extensions.Hosting;
1112
using Microsoft.EntityFrameworkCore;
1213
using Microsoft.EntityFrameworkCore.Infrastructure;
1314
using Microsoft.EntityFrameworkCore.Migrations;
@@ -191,26 +192,30 @@ private void DropDatabaseTables(IServiceProvider services)
191192

192193
public static void Main(string[] args)
193194
{
194-
var host = CreateWebHostBuilder(args)
195+
using var host = CreateHost(args)
195196
.Build();
196197

197198
host.Run();
198199
}
199200

200-
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
201+
public static IHostBuilder CreateHost(string[] args)
201202
{
202203
var configuration = new ConfigurationBuilder()
203204
.AddEnvironmentVariables()
204205
.AddCommandLine(args)
205206
.Build();
206207

207-
return new WebHostBuilder()
208-
.UseKestrel()
209-
.UseUrls("http://+:5000")
210-
.UseConfiguration(configuration)
211-
.UseIISIntegration()
212-
.UseContentRoot(Directory.GetCurrentDirectory())
213-
.UseStartup<Startup>();
208+
return new HostBuilder()
209+
.ConfigureWebHost(webHostBuilder =>
210+
{
211+
webHostBuilder
212+
.UseKestrel()
213+
.UseUrls("http://+:5000")
214+
.UseConfiguration(configuration)
215+
.UseIISIntegration()
216+
.UseContentRoot(Directory.GetCurrentDirectory())
217+
.UseStartup<Startup>();
218+
});
214219
}
215220
}
216221
}

src/Mvc/perf/benchmarkapps/RazorRendering/Startup.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Data;
55
using Microsoft.AspNetCore.Builder;
66
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.Extensions.Hosting;
78
using Microsoft.AspNetCore.Mvc;
89
using Microsoft.Extensions.DependencyInjection;
910
using Microsoft.AspNetCore.Html;
@@ -60,24 +61,28 @@ private static List<DataB> GenerateDataB()
6061

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

6667
host.Run();
6768
}
6869

69-
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
70+
public static IHostBuilder CreateHost(string[] args)
7071
{
7172
var configuration = new ConfigurationBuilder()
7273
.AddEnvironmentVariables()
7374
.AddCommandLine(args)
7475
.Build();
7576

76-
return new WebHostBuilder()
77-
.UseKestrel()
78-
.UseUrls("http://+:5000")
79-
.UseConfiguration(configuration)
80-
.UseContentRoot(Directory.GetCurrentDirectory())
81-
.UseStartup<Startup>();
77+
return new HostBuilder()
78+
.ConfigureWebHost(webHostBuilder =>
79+
{
80+
webHostBuilder
81+
.UseKestrel()
82+
.UseUrls("http://+:5000")
83+
.UseConfiguration(configuration)
84+
.UseContentRoot(Directory.GetCurrentDirectory())
85+
.UseStartup<Startup>();
86+
});
8287
}
8388
}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
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 CorsWebSite;
57

68
public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
var host = CreateWebHostBuilder(args)
12+
using var host = CreateHost(args)
1113
.Build();
1214

1315
host.Run();
1416
}
1517

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

src/Mvc/test/WebSites/FilesWebSite/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 FilesWebSite;
57

68
public class Startup
@@ -23,16 +25,20 @@ 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-
.UseStartup<Startup>()
36-
.UseKestrel()
37-
.UseIISIntegration();
34+
public static IHostBuilder CreateHost(string[] args) =>
35+
new HostBuilder()
36+
.ConfigureWebHost(webHostBuilder =>
37+
{
38+
webHostBuilder
39+
.UseContentRoot(Directory.GetCurrentDirectory())
40+
.UseStartup<Startup>()
41+
.UseKestrel()
42+
.UseIISIntegration();
43+
});
3844
}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
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 FormatterWebSite;
57

68
public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
var host = CreateWebHostBuilder(args)
12+
using var host = CreateHost(args)
1113
.Build();
1214

1315
host.Run();
1416
}
1517

16-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
17-
new WebHostBuilder()
18-
.UseContentRoot(Directory.GetCurrentDirectory())
19-
.UseStartup<Startup>()
20-
.UseKestrel()
21-
.UseIISIntegration();
18+
public static IHostBuilder CreateHost(string[] args) =>
19+
new HostBuilder()
20+
.ConfigureWebHost(webHostBuilder =>
21+
{
22+
webHostBuilder
23+
.UseContentRoot(Directory.GetCurrentDirectory())
24+
.UseStartup<Startup>()
25+
.UseKestrel()
26+
.UseIISIntegration();
27+
});
2228
}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
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 RazorPagesWebSite;
57

68
public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
var host = CreateWebHostBuilder(args)
12+
using var host = CreateHost(args)
1113
.Build();
1214

1315
host.Run();
1416
}
1517

16-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
17-
new WebHostBuilder()
18-
.UseKestrel()
19-
.UseContentRoot(Directory.GetCurrentDirectory())
20-
.UseIISIntegration()
21-
.UseStartup<StartupWithBasePath>();
18+
public static IHostBuilder CreateHost(string[] args) =>
19+
new HostBuilder()
20+
.ConfigureWebHost(webHostBuilder =>
21+
{
22+
webHostBuilder
23+
.UseKestrel()
24+
.UseContentRoot(Directory.GetCurrentDirectory())
25+
.UseIISIntegration()
26+
.UseStartup<StartupWithBasePath>();
27+
});
2228
}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
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 RazorWebSite;
57

68
public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
var host = CreateWebHostBuilder(args)
12+
using var host = CreateHost(args)
1113
.Build();
1214

1315
host.Run();
1416
}
1517

16-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
17-
new WebHostBuilder()
18-
.UseContentRoot(Directory.GetCurrentDirectory())
19-
.UseStartup<Startup>()
20-
.UseKestrel()
21-
.UseIISIntegration();
18+
public static IHostBuilder CreateHost(string[] args) =>
19+
new HostBuilder()
20+
.ConfigureWebHost(webHostBuilder =>
21+
{
22+
webHostBuilder
23+
.UseContentRoot(Directory.GetCurrentDirectory())
24+
.UseStartup<Startup>()
25+
.UseKestrel()
26+
.UseIISIntegration();
27+
});
2228
}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
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 RoutingWebSite;
57

68
public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
var host = CreateWebHostBuilder(args)
12+
using var host = CreateHost(args)
1113
.Build();
1214

1315
host.Run();
1416
}
1517

16-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
17-
new WebHostBuilder()
18-
.UseContentRoot(Directory.GetCurrentDirectory())
19-
.UseStartup<StartupForFallback>()
20-
.UseKestrel()
21-
.UseIISIntegration();
18+
public static IHostBuilder CreateHost(string[] args) =>
19+
new HostBuilder()
20+
.ConfigureWebHost(webHostBuilder =>
21+
{
22+
webHostBuilder
23+
.UseContentRoot(Directory.GetCurrentDirectory())
24+
.UseStartup<StartupForFallback>()
25+
.UseKestrel()
26+
.UseIISIntegration();
27+
});
2228
}
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
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 SecurityWebSite;
57

68
public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
var host = CreateWebHostBuilder(args)
12+
using var host = CreateHost(args)
1113
.Build();
1214

1315
host.Run();
1416
}
1517

16-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
17-
new WebHostBuilder()
18-
.UseKestrel()
19-
.UseContentRoot(Directory.GetCurrentDirectory())
20-
.UseStartup<Startup>();
18+
public static IHostBuilder CreateHost(string[] args) =>
19+
new HostBuilder()
20+
.ConfigureWebHost(webHostBuilder =>
21+
{
22+
webHostBuilder
23+
.UseKestrel()
24+
.UseContentRoot(Directory.GetCurrentDirectory())
25+
.UseStartup<Startup>();
26+
});
2127
}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
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 VersioningWebSite;
57

68
public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
var host = CreateWebHostBuilder(args)
12+
using var host = CreateHost(args)
1113
.Build();
1214

1315
host.Run();
1416
}
1517

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

0 commit comments

Comments
 (0)