Skip to content

Commit 9a4eb51

Browse files
authored
[Azure] Move to GenericHost (#24283)
1 parent e23f83d commit 9a4eb51

File tree

4 files changed

+60
-35
lines changed

4 files changed

+60
-35
lines changed
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.IO;
5+
using System.Threading.Tasks;
56
using Microsoft.AspNetCore.Hosting;
67
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.Hosting;
79
using Microsoft.Extensions.Logging;
810

911
namespace AzureADB2CSample
1012
{
1113
public class Program
1214
{
13-
public static void Main(string[] args)
15+
public static Task Main(string[] args)
1416
{
15-
CreateWebHostBuilder(args).Build().Run();
16-
}
17-
18-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
19-
new WebHostBuilder()
20-
.UseContentRoot(Directory.GetCurrentDirectory())
21-
.ConfigureAppConfiguration((hostingContext, config) =>{
17+
var host = new HostBuilder()
18+
.ConfigureWebHost(webHostBuilder =>
19+
{
20+
webHostBuilder
21+
.UseContentRoot(Directory.GetCurrentDirectory())
22+
.UseIISIntegration()
23+
.UseKestrel()
24+
.UseStartup<Startup>();
25+
})
26+
.ConfigureAppConfiguration((hostingContext, config) =>
27+
{
2228
var env = hostingContext.HostingEnvironment;
2329

2430
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
@@ -32,8 +38,9 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
3238
.AddConsole()
3339
.AddDebug();
3440
})
35-
.UseIISIntegration()
36-
.UseKestrel()
37-
.UseStartup<Startup>();
41+
.Build();
42+
43+
return host.RunAsync();
44+
}
3845
}
3946
}

src/Azure/AzureAD/samples/AzureADSample/Program.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.IO;
5+
using System.Threading.Tasks;
56
using Microsoft.AspNetCore.Hosting;
67
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.Hosting;
79
using Microsoft.Extensions.Logging;
810

911
namespace AzureADSample
1012
{
1113
public class Program
1214
{
13-
public static void Main(string[] args)
15+
public static Task Main(string[] args)
1416
{
15-
CreateWebHostBuilder(args).Build().Run();
16-
}
17-
18-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
19-
new WebHostBuilder()
20-
.UseContentRoot(Directory.GetCurrentDirectory())
21-
.ConfigureAppConfiguration((hostingContext, config) =>{
17+
var host = new HostBuilder()
18+
.ConfigureWebHost(webHostBuilder =>
19+
{
20+
webHostBuilder
21+
.UseContentRoot(Directory.GetCurrentDirectory())
22+
.UseIISIntegration()
23+
.UseKestrel()
24+
.UseStartup<Startup>();
25+
})
26+
.ConfigureAppConfiguration((hostingContext, config) =>
27+
{
2228
var env = hostingContext.HostingEnvironment;
2329

2430
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
@@ -32,8 +38,9 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
3238
.AddConsole()
3339
.AddDebug();
3440
})
35-
.UseIISIntegration()
36-
.UseKestrel()
37-
.UseStartup<Startup>();
41+
.Build();
42+
43+
return host.RunAsync();
44+
}
3845
}
3946
}

src/Azure/samples/AzureAppServicesHostingStartupSample/Startup.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Linq;
3+
using System.Threading.Tasks;
34
using Microsoft.AspNetCore.Builder;
45
using Microsoft.AspNetCore.Hosting;
56
using Microsoft.AspNetCore.Http;
7+
using Microsoft.Extensions.Hosting;
68
using Microsoft.Extensions.Logging;
79

810
namespace IISSample
@@ -58,18 +60,22 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
5860
});
5961
}
6062

61-
public static void Main(string[] args)
63+
public static Task Main(string[] args)
6264
{
63-
var host = new WebHostBuilder()
65+
var host = new HostBuilder()
66+
.ConfigureWebHost(webHostBuilder =>
67+
{
68+
webHostBuilder
69+
.UseKestrel()
70+
.UseStartup<Startup>();
71+
})
6472
.ConfigureLogging(factory =>
6573
{
6674
factory.AddConsole();
6775
})
68-
.UseKestrel()
69-
.UseStartup<Startup>()
7076
.Build();
7177

72-
host.Run();
78+
return host.RunAsync();
7379
}
7480
}
7581
}

src/Azure/samples/AzureAppServicesSample/Startup.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
22
using System.Linq;
3+
using System.Threading.Tasks;
34
using Microsoft.AspNetCore.Builder;
45
using Microsoft.AspNetCore.Hosting;
56
using Microsoft.AspNetCore.Http;
67
using Microsoft.Extensions.DependencyInjection;
8+
using Microsoft.Extensions.Hosting;
79
using Microsoft.Extensions.Logging;
810

911
namespace IISSample
@@ -70,20 +72,23 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
7072
});
7173
}
7274

73-
public static void Main(string[] args)
75+
public static Task Main(string[] args)
7476
{
75-
var host = new WebHostBuilder()
77+
var host = new HostBuilder()
78+
.ConfigureWebHost(webHostBuilder =>
79+
{
80+
webHostBuilder
81+
.UseKestrel()
82+
.UseAzureAppServices()
83+
.UseStartup<Startup>();
84+
})
7685
.ConfigureLogging(factory =>
7786
{
7887
factory.AddConsole();
7988
})
80-
.UseKestrel()
81-
.UseAzureAppServices()
82-
.UseStartup<Startup>()
8389
.Build();
8490

85-
host.Run();
91+
return host.RunAsync();
8692
}
8793
}
8894
}
89-

0 commit comments

Comments
 (0)