Skip to content

Commit b90ef6b

Browse files
committed
more targeted
1 parent 38877f9 commit b90ef6b

File tree

11 files changed

+40
-19
lines changed

11 files changed

+40
-19
lines changed

src/DefaultBuilder/samples/SampleApp/Program.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,9 @@ private static void CustomApplicationBuilder()
7575
}
7676
private static void DirectWebHost(string[] args)
7777
{
78-
// Using defaults with HostBuilder pattern
79-
using (var host = Host.CreateDefaultBuilder(args)
80-
.ConfigureWebHostDefaults(webBuilder =>
81-
{
82-
webBuilder.UseStartup<Startup>();
83-
})
78+
// Using defaults with a Startup class
79+
using (var host = WebHost.CreateDefaultBuilder(args)
80+
.UseStartup<Startup>()
8481
.Build())
8582
{
8683
host.Run();

src/DefaultBuilder/src/ConfigureWebHostBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace Microsoft.AspNetCore.Builder;
1313
/// A non-buildable <see cref="IWebHostBuilder"/> for <see cref="WebApplicationBuilder"/>.
1414
/// Use <see cref="WebApplicationBuilder.Build"/> to build the <see cref="WebApplicationBuilder"/>.
1515
/// </summary>
16-
#pragma warning disable CS0618 // Type or member is obsolete
1716
public sealed class ConfigureWebHostBuilder : IWebHostBuilder, ISupportsStartup
1817
{
1918
private readonly IWebHostEnvironment _environment;
@@ -29,10 +28,12 @@ internal ConfigureWebHostBuilder(WebHostBuilderContext webHostBuilderContext, Co
2928
_context = webHostBuilderContext;
3029
}
3130

31+
#pragma warning disable CS0618 // Type or member is obsolete
3232
IWebHost IWebHostBuilder.Build()
3333
{
3434
throw new NotSupportedException($"Call {nameof(WebApplicationBuilder)}.{nameof(WebApplicationBuilder.Build)}() instead.");
3535
}
36+
#pragma warning restore CS0618 // Type or member is obsolete
3637

3738
/// <inheritdoc />
3839
public IWebHostBuilder ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureDelegate)
@@ -184,4 +185,3 @@ IWebHostBuilder ISupportsStartup.UseStartup([DynamicallyAccessedMembers(StartupL
184185
throw new NotSupportedException("UseStartup() is not supported by WebApplicationBuilder.WebHost. Use the WebApplication returned by WebApplicationBuilder.Build() instead.");
185186
}
186187
}
187-
#pragma warning restore CS0618 // Type or member is obsolete

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 CS0618 // Type or member is obsolete
380381
Assert.Throws<NotSupportedException>(() => ((IWebHostBuilder)createBuilder().WebHost).Build());
382+
#pragma warning restore CS0618 // Type or member is obsolete
381383
}
382384

383385
[Theory]

src/Hosting/Abstractions/src/IWebHostBuilder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ namespace Microsoft.AspNetCore.Hosting;
1010
/// <summary>
1111
/// A builder for <see cref="IWebHost"/>.
1212
/// </summary>
13-
#pragma warning disable CS0618 // Type or member is obsolete
1413
public interface IWebHostBuilder
1514
{
1615
/// <summary>
1716
/// Builds an <see cref="IWebHost"/> which hosts a web application.
1817
/// </summary>
18+
[Obsolete("IWebHost is obsolete. Use IHost instead.")]
1919
IWebHost Build();
2020

2121
/// <summary>
@@ -60,4 +60,3 @@ public interface IWebHostBuilder
6060
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
6161
IWebHostBuilder UseSetting(string key, string? value);
6262
}
63-
#pragma warning restore CS0618 // Type or member is obsolete

src/Hosting/Hosting/src/GenericHost/HostingStartupWebHostBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace Microsoft.AspNetCore.Hosting;
1212

1313
// We use this type to capture calls to the IWebHostBuilder so the we can properly order calls to
1414
// to GenericHostWebHostBuilder.
15-
#pragma warning disable CS0618 // Type or member is obsolete
1615
internal sealed class HostingStartupWebHostBuilder : IWebHostBuilder, ISupportsStartup, ISupportsUseDefaultServiceProvider
1716
{
1817
private readonly GenericWebHostBuilder _builder;
@@ -24,10 +23,12 @@ public HostingStartupWebHostBuilder(GenericWebHostBuilder builder)
2423
_builder = builder;
2524
}
2625

26+
#pragma warning disable CS0618 // Type or member is obsolete
2727
public IWebHost Build()
2828
{
2929
throw new NotSupportedException($"Building this implementation of {nameof(IWebHostBuilder)} is not supported.");
3030
}
31+
#pragma warning restore CS0618 // Type or member is obsolete
3132

3233
public IWebHostBuilder ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureDelegate)
3334
{
@@ -91,4 +92,3 @@ public IWebHostBuilder UseStartup([DynamicallyAccessedMembers(StartupLinkerOptio
9192
return _builder.UseStartup(startupFactory);
9293
}
9394
}
94-
#pragma warning restore CS0618 // Type or member is obsolete

src/Hosting/Hosting/src/GenericHost/WebHostBuilderBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Microsoft.AspNetCore.Hosting;
99

10-
#pragma warning disable CS0618 // Type or member is obsolete
1110
internal abstract class WebHostBuilderBase : IWebHostBuilder, ISupportsUseDefaultServiceProvider
1211
{
1312
private protected readonly IHostBuilder _builder;
@@ -27,10 +26,12 @@ public WebHostBuilderBase(IHostBuilder builder, WebHostBuilderOptions options)
2726
_config = configBuilder.Build();
2827
}
2928

29+
#pragma warning disable CS0618 // Type or member is obsolete
3030
public IWebHost Build()
3131
{
3232
throw new NotSupportedException($"Building this implementation of {nameof(IWebHostBuilder)} is not supported.");
3333
}
34+
#pragma warning restore CS0618 // Type or member is obsolete
3435

3536
public IWebHostBuilder ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureDelegate)
3637
{
@@ -106,4 +107,3 @@ public IWebHostBuilder UseSetting(string key, string? value)
106107
return this;
107108
}
108109
}
109-
#pragma warning restore CS0618 // Type or member is obsolete

src/Hosting/TestHost/src/TestServer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class TestServer : IServer
1818
{
1919
#pragma warning disable CS0618 // Type or member is obsolete
2020
private readonly IWebHost? _hostInstance;
21+
#pragma warning restore CS0618 // Type or member is obsolete
2122
private bool _disposed;
2223
private ApplicationWrapper? _application;
2324

@@ -79,6 +80,7 @@ public TestServer(IServiceProvider services, IFeatureCollection featureCollectio
7980
/// For use with IWebHostBuilder.
8081
/// </summary>
8182
/// <param name="builder"></param>
83+
[Obsolete("IWebHost, which this method uses, is obsolete. Use one of the ctors that takes an IServiceProvider instead.")]
8284
public TestServer(IWebHostBuilder builder)
8385
: this(builder, CreateTestFeatureCollection())
8486
{
@@ -89,6 +91,7 @@ public TestServer(IWebHostBuilder builder)
8991
/// </summary>
9092
/// <param name="builder"></param>
9193
/// <param name="featureCollection"></param>
94+
[Obsolete("IWebHost, which this method uses, is obsolete. Use one of the ctors that takes an IServiceProvider instead.")]
9295
public TestServer(IWebHostBuilder builder, IFeatureCollection featureCollection)
9396
{
9497
ArgumentNullException.ThrowIfNull(builder);
@@ -110,6 +113,7 @@ public TestServer(IWebHostBuilder builder, IFeatureCollection featureCollection)
110113
/// <summary>
111114
/// Gets the <see cref="IWebHost" /> instance associated with the test server.
112115
/// </summary>
116+
[Obsolete("IWebHost is obsolete. Use IHost instead.")]
113117
public IWebHost Host
114118
{
115119
get
@@ -118,7 +122,6 @@ public IWebHost Host
118122
?? throw new InvalidOperationException("The TestServer constructor was not called with a IWebHostBuilder so IWebHost is not available.");
119123
}
120124
}
121-
#pragma warning restore CS0618 // Type or member is obsolete
122125

123126
/// <summary>
124127
/// Gets the service provider associated with the test server.

src/Hosting/TestHost/src/WebHostBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace Microsoft.AspNetCore.TestHost;
1414
/// <summary>
1515
/// Contains extensions for configuring the <see cref="IWebHostBuilder" /> instance.
1616
/// </summary>
17-
#pragma warning disable CS0618 // Type or member is obsolete
1817
public static class WebHostBuilderExtensions
1918
{
2019
/// <summary>
@@ -52,6 +51,7 @@ public static IWebHostBuilder UseTestServer(this IWebHostBuilder builder, Action
5251
/// </summary>
5352
/// <param name="host"></param>
5453
/// <returns></returns>
54+
[Obsolete("IWebHost is obsolete. Use IHost instead.")]
5555
public static TestServer GetTestServer(this IWebHost host)
5656
{
5757
return (TestServer)host.Services.GetRequiredService<IServer>();
@@ -62,6 +62,7 @@ public static TestServer GetTestServer(this IWebHost host)
6262
/// </summary>
6363
/// <param name="host"></param>
6464
/// <returns></returns>
65+
[Obsolete("IWebHost is obsolete. Use IHost instead.")]
6566
public static HttpClient GetTestClient(this IWebHost host)
6667
{
6768
return host.GetTestServer().CreateClient();
@@ -209,4 +210,3 @@ public Action<TContainer> ConfigureContainer(Action<TContainer> next) =>
209210
};
210211
}
211212
}
212-
#pragma warning restore CS0618 // Type or member is obsolete

src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ namespace Microsoft.AspNetCore.Mvc.Testing;
2323
/// </summary>
2424
/// <typeparam name="TEntryPoint">A type in the entry point assembly of the application.
2525
/// Typically the Startup or Program classes can be used.</typeparam>
26-
#pragma warning disable CS0618 // Type or member is obsolete
2726
public partial class WebApplicationFactory<TEntryPoint> : IDisposable, IAsyncDisposable where TEntryPoint : class
2827
{
2928
private bool _disposed;
@@ -36,7 +35,9 @@ public partial class WebApplicationFactory<TEntryPoint> : IDisposable, IAsyncDis
3635
private TestServer? _server;
3736
private IHost? _host;
3837
private Action<IWebHostBuilder> _configuration;
38+
#pragma warning disable CS0618 // Type or member is obsolete
3939
private IWebHost? _webHost;
40+
#pragma warning restore CS0618 // Type or member is obsolete
4041
private Uri? _webHostAddress;
4142
private readonly List<HttpClient> _clients = new();
4243
private readonly List<WebApplicationFactory<TEntryPoint>> _derivedFactories = new();
@@ -107,7 +108,9 @@ public virtual IServiceProvider Services
107108
return _webHost?.Services ?? _host!.Services;
108109
}
109110

111+
#pragma warning disable CS0618 // Type or member is obsolete
110112
return _host?.Services ?? _server!.Host.Services;
113+
#pragma warning restore CS0618 // Type or member is obsolete
111114
}
112115
}
113116

@@ -143,7 +146,9 @@ internal virtual WebApplicationFactory<TEntryPoint> WithWebHostBuilderCore(Actio
143146
{
144147
var factory = new DelegatedWebApplicationFactory(
145148
ClientOptions,
149+
#pragma warning disable CS0618 // Type or member is obsolete
146150
CreateServer,
151+
#pragma warning restore CS0618 // Type or member is obsolete
147152
CreateServer,
148153
CreateHost,
149154
CreateWebHostBuilder,
@@ -202,6 +207,7 @@ public void UseKestrel(Action<KestrelServerOptions> configureKestrelOptions)
202207
this._configureKestrelOptions = configureKestrelOptions;
203208
}
204209

210+
#pragma warning disable CS0618 // Type or member is obsolete
205211
private IWebHost CreateKestrelServer(IWebHostBuilder builder)
206212
{
207213
ConfigureBuilderToUseKestrel(builder);
@@ -213,6 +219,7 @@ private IWebHost CreateKestrelServer(IWebHostBuilder builder)
213219
host.Start();
214220
return host;
215221
}
222+
#pragma warning restore CS0618 // Type or member is obsolete
216223

217224
private void TryConfigureServerPort(Func<IServerAddressesFeature?> serverAddressFeatureAccessor)
218225
{
@@ -312,7 +319,9 @@ public void StartServer()
312319
}
313320
else
314321
{
322+
#pragma warning disable CS0618 // Type or member is obsolete
315323
_server = CreateServer(builder);
324+
#pragma warning restore CS0618 // Type or member is obsolete
316325
}
317326
}
318327
}
@@ -568,6 +577,7 @@ private static void EnsureDepsFile()
568577
/// <param name="builder">The <see cref="IWebHostBuilder"/> used to
569578
/// create the server.</param>
570579
/// <returns>The <see cref="TestServer"/> with the bootstrapped application.</returns>
580+
[Obsolete("IWebHost, which this method uses, is obsolete. Use one of the ctors that takes an IServiceProvider instead.")]
571581
protected virtual TestServer CreateServer(IWebHostBuilder builder) => new(builder);
572582

573583
/// <summary>
@@ -596,7 +606,9 @@ protected virtual IHost CreateHost(IHostBuilder builder)
596606

597607
private static IServerAddressesFeature? GetServerAddressFeature(IHost host) => host.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>();
598608

609+
#pragma warning disable CS0618 // Type or member is obsolete
599610
private static IServerAddressesFeature? GetServerAddressFeature(IWebHost webHost) => webHost.ServerFeatures.Get<IServerAddressesFeature>();
611+
#pragma warning restore CS0618 // Type or member is obsolete
600612

601613
/// <summary>
602614
/// Gives a fixture an opportunity to configure the application before it gets built.
@@ -844,6 +856,7 @@ public DelegatedWebApplicationFactory(
844856
_configuration = configureWebHost;
845857
}
846858

859+
[Obsolete("IWebHost, which this method uses, is obsolete. Use one of the ctors that takes an IServiceProvider instead.")]
847860
protected override TestServer CreateServer(IWebHostBuilder builder) => _createServer(builder);
848861

849862
protected override TestServer CreateServer(IServiceProvider serviceProvider) => _createServerFromServiceProvider(serviceProvider);
@@ -879,4 +892,3 @@ internal override WebApplicationFactory<TEntryPoint> WithWebHostBuilderCore(Acti
879892
}
880893
}
881894
}
882-
#pragma warning restore CS0618 // Type or member is obsolete

src/Mvc/test/Mvc.FunctionalTests/Infrastructure/MvcTestFixture.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
4242
});
4343
}
4444

45+
#pragma warning disable CS0672 // Member overrides obsolete member
4546
protected override TestServer CreateServer(IWebHostBuilder builder)
47+
#pragma warning restore CS0672 // Member overrides obsolete member
4648
{
4749
var originalCulture = CultureInfo.CurrentCulture;
4850
var originalUICulture = CultureInfo.CurrentUICulture;
4951
try
5052
{
5153
CultureInfo.CurrentCulture = new CultureInfo("en-GB");
5254
CultureInfo.CurrentUICulture = new CultureInfo("en-US");
55+
#pragma warning disable CS0618 // Type or member is obsolete
5356
return base.CreateServer(builder);
57+
#pragma warning restore CS0618 // Type or member is obsolete
5458
}
5559
finally
5660
{

0 commit comments

Comments
 (0)