Skip to content

Commit fe0ccd9

Browse files
authored
Add [Obsolete] attribute to WebHost, IWebHost, and WebHostService
Added ASPDEPR008 diagnostic code for WebHost and IWebHost related APIs Added ASPDEPR009 diagnostic code for WebHostService and related APIs
1 parent 28bbfc3 commit fe0ccd9

File tree

53 files changed

+282
-106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+282
-106
lines changed
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +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.AspNetCore;
4+
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.Extensions.Hosting;
56

67
namespace ComponentsApp.Server;
78

@@ -12,10 +13,13 @@ public static void Main(string[] args)
1213
BuildWebHost(args).Run();
1314
}
1415

15-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
16-
WebHost.CreateDefaultBuilder(args)
17-
.UseStartup<Startup>();
16+
public static IHostBuilder CreateHostBuilder(string[] args) =>
17+
Host.CreateDefaultBuilder(args)
18+
.ConfigureWebHostDefaults(webBuilder =>
19+
{
20+
webBuilder.UseStartup<Startup>();
21+
});
1822

19-
public static IWebHost BuildWebHost(string[] args) =>
20-
CreateWebHostBuilder(args).Build();
23+
public static IHost BuildWebHost(string[] args) =>
24+
CreateHostBuilder(args).Build();
2125
}

src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/HostingTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public async Task WebhostLoadsKeyRingBeforeServerStarts()
3636
new FakeServer(onStart: () => tcs.TrySetException(new InvalidOperationException("Server was started before key ring was initialized")))));
3737
#pragma warning restore ASPDEPR004 // Type or member is obsolete
3838

39+
#pragma warning disable ASPDEPR008 // IWebHost is obsolete
3940
using (var host = builder.Build())
41+
#pragma warning restore ASPDEPR008 // IWebHost is obsolete
4042
{
4143
await host.StartAsync();
4244
}

src/DefaultBuilder/samples/SampleApp/Program.cs

Lines changed: 2 additions & 0 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+
#pragma warning disable ASPDEPR008 // Type or member is obsolete
5+
46
using Microsoft.AspNetCore;
57

68
namespace SampleApp;

src/DefaultBuilder/src/ConfigureWebHostBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ internal ConfigureWebHostBuilder(WebHostBuilderContext webHostBuilderContext, Co
2828
_context = webHostBuilderContext;
2929
}
3030

31+
#pragma warning disable ASPDEPR008 // IWebHost is obsolete
3132
IWebHost IWebHostBuilder.Build()
3233
{
3334
throw new NotSupportedException($"Call {nameof(WebApplicationBuilder)}.{nameof(WebApplicationBuilder.Build)}() instead.");
3435
}
36+
#pragma warning restore ASPDEPR008 // IWebHost is obsolete
3537

3638
/// <inheritdoc />
3739
public IWebHostBuilder ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureDelegate)

src/DefaultBuilder/src/GenericHostBuilderExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public static IHostBuilder ConfigureWebHostDefaults(this IHostBuilder builder, A
6161

6262
return builder.ConfigureWebHost(webHostBuilder =>
6363
{
64+
#pragma warning disable ASPDEPR008 // Type or member is obsolete
6465
WebHost.ConfigureWebDefaults(webHostBuilder);
66+
#pragma warning restore ASPDEPR008 // Type or member is obsolete
6567

6668
configure(webHostBuilder);
6769
}, configureOptions);

src/DefaultBuilder/src/WebApplicationBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ internal WebApplicationBuilder(WebApplicationOptions options, bool slim, Action<
127127
bootstrapHostBuilder.ConfigureSlimWebHost(
128128
webHostBuilder =>
129129
{
130+
#pragma warning disable ASPDEPR008 // Type or member is obsolete
130131
AspNetCore.WebHost.ConfigureWebDefaultsSlim(webHostBuilder);
132+
#pragma warning restore ASPDEPR008 // Type or member is obsolete
131133

132134
// Runs inline.
133135
webHostBuilder.Configure(ConfigureApplication);

src/DefaultBuilder/src/WebHost.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Microsoft.AspNetCore;
2121
/// <summary>
2222
/// Provides convenience methods for creating instances of <see cref="IWebHost"/> and <see cref="IWebHostBuilder"/> with pre-configured defaults.
2323
/// </summary>
24+
[Obsolete("WebHost is obsolete. Use HostBuilder or WebApplicationBuilder instead. For more information, visit https://aka.ms/aspnet/deprecate/008.", DiagnosticId = "ASPDEPR008")]
2425
public static class WebHost
2526
{
2627
/// <summary>

src/DefaultBuilder/test/Microsoft.AspNetCore.FunctionalTests/WebHostFunctionalTests.cs

Lines changed: 2 additions & 0 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+
#pragma warning disable ASPDEPR008 // Type or member is obsolete
5+
46
using System.Net.Http;
57
using Microsoft.AspNetCore.Http;
68
using Microsoft.AspNetCore.Server.IntegrationTesting;

src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebApplicationTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ public void WebApplicationBuilderHost_ThrowsWhenBuiltDirectly(CreateBuilderFunc
377377
[MemberData(nameof(CreateBuilderFuncs))]
378378
public void WebApplicationBuilderWebHost_ThrowsWhenBuiltDirectly(CreateBuilderFunc createBuilder)
379379
{
380+
#pragma warning disable ASPDEPR008 // IWebHost is obsolete
380381
Assert.Throws<NotSupportedException>(() => ((IWebHostBuilder)createBuilder().WebHost).Build());
382+
#pragma warning restore ASPDEPR008 // IWebHost is obsolete
381383
}
382384

383385
[Theory]

src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebHostTests.cs

Lines changed: 2 additions & 0 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+
#pragma warning disable ASPDEPR008 // IWebHost is obsolete
5+
46
using System.Collections.Concurrent;
57
using System.Diagnostics.Tracing;
68
using Microsoft.AspNetCore.Builder;

0 commit comments

Comments
 (0)