diff --git a/src/Components/test/testassets/ComponentsApp.Server/Program.cs b/src/Components/test/testassets/ComponentsApp.Server/Program.cs index 1fb78e81f354..93f34b504d12 100644 --- a/src/Components/test/testassets/ComponentsApp.Server/Program.cs +++ b/src/Components/test/testassets/ComponentsApp.Server/Program.cs @@ -1,7 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; namespace ComponentsApp.Server; @@ -12,10 +13,13 @@ public static void Main(string[] args) BuildWebHost(args).Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); - public static IWebHost BuildWebHost(string[] args) => - CreateWebHostBuilder(args).Build(); + public static IHost BuildWebHost(string[] args) => + CreateHostBuilder(args).Build(); } diff --git a/src/DefaultBuilder/samples/SampleApp/Program.cs b/src/DefaultBuilder/samples/SampleApp/Program.cs index fa29b18ac461..6b30b6c4c8f7 100644 --- a/src/DefaultBuilder/samples/SampleApp/Program.cs +++ b/src/DefaultBuilder/samples/SampleApp/Program.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using Microsoft.AspNetCore; namespace SampleApp; @@ -73,9 +75,12 @@ private static void CustomApplicationBuilder() } private static void DirectWebHost(string[] args) { - // Using defaults with a Startup class - using (var host = WebHost.CreateDefaultBuilder(args) - .UseStartup() + // Using defaults with HostBuilder pattern + using (var host = Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) .Build()) { host.Run(); diff --git a/src/DefaultBuilder/src/ConfigureWebHostBuilder.cs b/src/DefaultBuilder/src/ConfigureWebHostBuilder.cs index bd99297c8e56..e0fb8a86be07 100644 --- a/src/DefaultBuilder/src/ConfigureWebHostBuilder.cs +++ b/src/DefaultBuilder/src/ConfigureWebHostBuilder.cs @@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Builder; /// A non-buildable for . /// Use to build the . /// +#pragma warning disable CS0618 // Type or member is obsolete public sealed class ConfigureWebHostBuilder : IWebHostBuilder, ISupportsStartup { private readonly IWebHostEnvironment _environment; @@ -183,3 +184,4 @@ IWebHostBuilder ISupportsStartup.UseStartup([DynamicallyAccessedMembers(StartupL throw new NotSupportedException("UseStartup() is not supported by WebApplicationBuilder.WebHost. Use the WebApplication returned by WebApplicationBuilder.Build() instead."); } } +#pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/DefaultBuilder/src/GenericHostBuilderExtensions.cs b/src/DefaultBuilder/src/GenericHostBuilderExtensions.cs index f61d482b4066..483fcc34568b 100644 --- a/src/DefaultBuilder/src/GenericHostBuilderExtensions.cs +++ b/src/DefaultBuilder/src/GenericHostBuilderExtensions.cs @@ -61,7 +61,9 @@ public static IHostBuilder ConfigureWebHostDefaults(this IHostBuilder builder, A return builder.ConfigureWebHost(webHostBuilder => { +#pragma warning disable CS0618 // Type or member is obsolete WebHost.ConfigureWebDefaults(webHostBuilder); +#pragma warning restore CS0618 // Type or member is obsolete configure(webHostBuilder); }, configureOptions); diff --git a/src/DefaultBuilder/src/WebApplicationBuilder.cs b/src/DefaultBuilder/src/WebApplicationBuilder.cs index 2cff4ae4ffb9..409e724eee63 100644 --- a/src/DefaultBuilder/src/WebApplicationBuilder.cs +++ b/src/DefaultBuilder/src/WebApplicationBuilder.cs @@ -127,7 +127,9 @@ internal WebApplicationBuilder(WebApplicationOptions options, bool slim, Action< bootstrapHostBuilder.ConfigureSlimWebHost( webHostBuilder => { +#pragma warning disable CS0618 // Type or member is obsolete AspNetCore.WebHost.ConfigureWebDefaultsSlim(webHostBuilder); +#pragma warning restore CS0618 // Type or member is obsolete // Runs inline. webHostBuilder.Configure(ConfigureApplication); diff --git a/src/DefaultBuilder/src/WebHost.cs b/src/DefaultBuilder/src/WebHost.cs index 1c3b9b4f07fe..ad14b7e93485 100644 --- a/src/DefaultBuilder/src/WebHost.cs +++ b/src/DefaultBuilder/src/WebHost.cs @@ -21,6 +21,7 @@ namespace Microsoft.AspNetCore; /// /// Provides convenience methods for creating instances of and with pre-configured defaults. /// +[Obsolete("WebHost is obsolete. Use HostBuilder or WebApplicationBuilder instead.")] public static class WebHost { /// diff --git a/src/DefaultBuilder/test/Microsoft.AspNetCore.FunctionalTests/WebHostFunctionalTests.cs b/src/DefaultBuilder/test/Microsoft.AspNetCore.FunctionalTests/WebHostFunctionalTests.cs index 94a64ffc74fc..52155915c0fe 100644 --- a/src/DefaultBuilder/test/Microsoft.AspNetCore.FunctionalTests/WebHostFunctionalTests.cs +++ b/src/DefaultBuilder/test/Microsoft.AspNetCore.FunctionalTests/WebHostFunctionalTests.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using System.Net.Http; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.IntegrationTesting; diff --git a/src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebHostTests.cs b/src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebHostTests.cs index 8205e1459a08..aff27723a8b0 100644 --- a/src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebHostTests.cs +++ b/src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebHostTests.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using System.Collections.Concurrent; using System.Diagnostics.Tracing; using Microsoft.AspNetCore.Builder; diff --git a/src/DefaultBuilder/testassets/CreateDefaultBuilderApp/Program.cs b/src/DefaultBuilder/testassets/CreateDefaultBuilderApp/Program.cs index 947c13abb87d..a3cbc83ab1c0 100644 --- a/src/DefaultBuilder/testassets/CreateDefaultBuilderApp/Program.cs +++ b/src/DefaultBuilder/testassets/CreateDefaultBuilderApp/Program.cs @@ -2,11 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace CreateDefaultBuilderApp; @@ -16,23 +16,27 @@ static void Main(string[] args) { string responseMessage = null; - WebHost.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" }) - .ConfigureServices((context, services) => responseMessage = responseMessage ?? GetResponseMessage(context)) - .ConfigureKestrel(options => options - .Configure(options.ConfigurationLoader.Configuration) - .Endpoint("HTTP", endpointOptions => - { - if (responseMessage == null - && !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"])) - { - responseMessage = "Default Kestrel configuration not read."; - } - })) - .Configure(app => app.Run(context => + Host.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" }) + .ConfigureWebHostDefaults(webBuilder => { - var hostingEnvironment = app.ApplicationServices.GetRequiredService(); - return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName); - })) + webBuilder + .ConfigureServices((context, services) => responseMessage = responseMessage ?? GetResponseMessage(context)) + .ConfigureKestrel(options => options + .Configure(options.ConfigurationLoader.Configuration) + .Endpoint("HTTP", endpointOptions => + { + if (responseMessage == null + && !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"])) + { + responseMessage = "Default Kestrel configuration not read."; + } + })) + .Configure(app => app.Run(context => + { + var hostingEnvironment = app.ApplicationServices.GetRequiredService(); + return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName); + })); + }) .Build().Run(); } diff --git a/src/DefaultBuilder/testassets/CreateDefaultBuilderOfTApp/Program.cs b/src/DefaultBuilder/testassets/CreateDefaultBuilderOfTApp/Program.cs index e5a9e22f8e23..cd96ae23e1f9 100644 --- a/src/DefaultBuilder/testassets/CreateDefaultBuilderOfTApp/Program.cs +++ b/src/DefaultBuilder/testassets/CreateDefaultBuilderOfTApp/Program.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.HostFiltering; using Microsoft.AspNetCore.Hosting; @@ -19,31 +18,35 @@ static void Main(string[] args) { string responseMessage = null; - WebHost.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" }) - .ConfigureServices((context, service) => responseMessage = responseMessage ?? GetResponseMessage(context)) - .ConfigureKestrel(options => options - .Configure(options.ConfigurationLoader.Configuration) - .Endpoint("HTTP", endpointOptions => - { - if (responseMessage == null - && !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"])) - { - responseMessage = "Default Kestrel configuration not read."; - } - })) - .Configure(app => app.Run(context => + Host.CreateDefaultBuilder(new[] { "--cliKey", "cliValue" }) + .ConfigureWebHostDefaults(webBuilder => { - // Verify allowed hosts were loaded - var hostFilteringOptions = app.ApplicationServices.GetRequiredService>(); - var hosts = string.Join(',', hostFilteringOptions.Value.AllowedHosts); - if (responseMessage == null && !string.Equals("example.com,127.0.0.1", hosts, StringComparison.Ordinal)) - { - responseMessage = "AllowedHosts not loaded into Options."; - } + webBuilder + .ConfigureServices((context, service) => responseMessage = responseMessage ?? GetResponseMessage(context)) + .ConfigureKestrel(options => options + .Configure(options.ConfigurationLoader.Configuration) + .Endpoint("HTTP", endpointOptions => + { + if (responseMessage == null + && !string.Equals("KestrelEndPointSettingValue", endpointOptions.ConfigSection["KestrelEndPointSettingName"])) + { + responseMessage = "Default Kestrel configuration not read."; + } + })) + .Configure(app => app.Run(context => + { + // Verify allowed hosts were loaded + var hostFilteringOptions = app.ApplicationServices.GetRequiredService>(); + var hosts = string.Join(',', hostFilteringOptions.Value.AllowedHosts); + if (responseMessage == null && !string.Equals("example.com,127.0.0.1", hosts, StringComparison.Ordinal)) + { + responseMessage = "AllowedHosts not loaded into Options."; + } - var hostingEnvironment = app.ApplicationServices.GetRequiredService(); - return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName); - })) + var hostingEnvironment = app.ApplicationServices.GetRequiredService(); + return context.Response.WriteAsync(responseMessage ?? hostingEnvironment.ApplicationName); + })); + }) .Build() .Run(); } diff --git a/src/DefaultBuilder/testassets/DependencyInjectionApp/Program.cs b/src/DefaultBuilder/testassets/DependencyInjectionApp/Program.cs index 657b7940895d..6cd428fa86f8 100644 --- a/src/DefaultBuilder/testassets/DependencyInjectionApp/Program.cs +++ b/src/DefaultBuilder/testassets/DependencyInjectionApp/Program.cs @@ -1,12 +1,12 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace CreateDefaultBuilderApp; @@ -14,27 +14,31 @@ public class Program { static void Main(string[] args) { - WebHost.CreateDefaultBuilder() - .UseUrls("http://127.0.0.1:0") - .ConfigureServices((context, services) => + Host.CreateDefaultBuilder() + .ConfigureWebHostDefaults(webBuilder => { - services.AddSingleton(typeof(IService<>), typeof(Service<>)); - services.AddScoped(); - }) - .Configure(app => - { - app.Run(context => - { - try + webBuilder + .UseUrls("http://127.0.0.1:0") + .ConfigureServices((context, services) => { - context.RequestServices.GetService>(); - return context.Response.WriteAsync("Success"); - } - catch (Exception ex) + services.AddSingleton(typeof(IService<>), typeof(Service<>)); + services.AddScoped(); + }) + .Configure(app => { - return context.Response.WriteAsync(ex.ToString()); - } - }); + app.Run(context => + { + try + { + context.RequestServices.GetService>(); + return context.Response.WriteAsync("Success"); + } + catch (Exception ex) + { + return context.Response.WriteAsync(ex.ToString()); + } + }); + }); }) .Build().Run(); } diff --git a/src/DefaultBuilder/testassets/StartRequestDelegateUrlApp/Program.cs b/src/DefaultBuilder/testassets/StartRequestDelegateUrlApp/Program.cs index f2cadf086c50..3ba489e9a68b 100644 --- a/src/DefaultBuilder/testassets/StartRequestDelegateUrlApp/Program.cs +++ b/src/DefaultBuilder/testassets/StartRequestDelegateUrlApp/Program.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using System; using System.Threading; using Microsoft.AspNetCore; diff --git a/src/DefaultBuilder/testassets/StartRouteBuilderUrlApp/Program.cs b/src/DefaultBuilder/testassets/StartRouteBuilderUrlApp/Program.cs index 46980d54399d..522d4ad4e1c3 100644 --- a/src/DefaultBuilder/testassets/StartRouteBuilderUrlApp/Program.cs +++ b/src/DefaultBuilder/testassets/StartRouteBuilderUrlApp/Program.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using System; using System.Threading; using Microsoft.AspNetCore; diff --git a/src/DefaultBuilder/testassets/StartWithIApplicationBuilderUrlApp/Program.cs b/src/DefaultBuilder/testassets/StartWithIApplicationBuilderUrlApp/Program.cs index c3422885bc75..2391f76b1da0 100644 --- a/src/DefaultBuilder/testassets/StartWithIApplicationBuilderUrlApp/Program.cs +++ b/src/DefaultBuilder/testassets/StartWithIApplicationBuilderUrlApp/Program.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using System; using System.Threading; using Microsoft.AspNetCore; diff --git a/src/Hosting/Abstractions/src/HostingAbstractionsWebHostBuilderExtensions.cs b/src/Hosting/Abstractions/src/HostingAbstractionsWebHostBuilderExtensions.cs index 930fde23ac41..35578d72cebf 100644 --- a/src/Hosting/Abstractions/src/HostingAbstractionsWebHostBuilderExtensions.cs +++ b/src/Hosting/Abstractions/src/HostingAbstractionsWebHostBuilderExtensions.cs @@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Hosting; /// /// Contains extension methods for configuring the . /// +#pragma warning disable CS0618 // Type or member is obsolete public static class HostingAbstractionsWebHostBuilderExtensions { /// @@ -176,3 +177,4 @@ public static IWebHost Start(this IWebHostBuilder hostBuilder, [StringSyntax(Str return host; } } +#pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/Hosting/Abstractions/src/IWebHost.cs b/src/Hosting/Abstractions/src/IWebHost.cs index b770ff5cee3d..be026303020a 100644 --- a/src/Hosting/Abstractions/src/IWebHost.cs +++ b/src/Hosting/Abstractions/src/IWebHost.cs @@ -8,6 +8,7 @@ namespace Microsoft.AspNetCore.Hosting; /// /// Represents a configured web host. /// +[Obsolete("IWebHost is obsolete. Use IHost instead.")] public interface IWebHost : IDisposable { /// diff --git a/src/Hosting/Abstractions/src/IWebHostBuilder.cs b/src/Hosting/Abstractions/src/IWebHostBuilder.cs index dd3fc81fd207..efbbbf944828 100644 --- a/src/Hosting/Abstractions/src/IWebHostBuilder.cs +++ b/src/Hosting/Abstractions/src/IWebHostBuilder.cs @@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.Hosting; /// /// A builder for . /// +#pragma warning disable CS0618 // Type or member is obsolete public interface IWebHostBuilder { /// @@ -59,3 +60,4 @@ public interface IWebHostBuilder /// The . IWebHostBuilder UseSetting(string key, string? value); } +#pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/Hosting/Hosting/src/GenericHost/HostingStartupWebHostBuilder.cs b/src/Hosting/Hosting/src/GenericHost/HostingStartupWebHostBuilder.cs index 85e384a1a2a7..844804ca69c7 100644 --- a/src/Hosting/Hosting/src/GenericHost/HostingStartupWebHostBuilder.cs +++ b/src/Hosting/Hosting/src/GenericHost/HostingStartupWebHostBuilder.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Hosting; // We use this type to capture calls to the IWebHostBuilder so the we can properly order calls to // to GenericHostWebHostBuilder. +#pragma warning disable CS0618 // Type or member is obsolete internal sealed class HostingStartupWebHostBuilder : IWebHostBuilder, ISupportsStartup, ISupportsUseDefaultServiceProvider { private readonly GenericWebHostBuilder _builder; @@ -90,3 +91,4 @@ public IWebHostBuilder UseStartup([DynamicallyAccessedMembers(StartupLinkerOptio return _builder.UseStartup(startupFactory); } } +#pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/Hosting/Hosting/src/GenericHost/WebHostBuilderBase.cs b/src/Hosting/Hosting/src/GenericHost/WebHostBuilderBase.cs index c104ed40002a..70dbd6d3dc74 100644 --- a/src/Hosting/Hosting/src/GenericHost/WebHostBuilderBase.cs +++ b/src/Hosting/Hosting/src/GenericHost/WebHostBuilderBase.cs @@ -7,6 +7,7 @@ namespace Microsoft.AspNetCore.Hosting; +#pragma warning disable CS0618 // Type or member is obsolete internal abstract class WebHostBuilderBase : IWebHostBuilder, ISupportsUseDefaultServiceProvider { private protected readonly IHostBuilder _builder; @@ -105,3 +106,4 @@ public IWebHostBuilder UseSetting(string key, string? value) return this; } } +#pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/Hosting/Hosting/src/Internal/WebHost.cs b/src/Hosting/Hosting/src/Internal/WebHost.cs index 6626cdda9889..e0b0857d982f 100644 --- a/src/Hosting/Hosting/src/Internal/WebHost.cs +++ b/src/Hosting/Hosting/src/Internal/WebHost.cs @@ -19,6 +19,7 @@ namespace Microsoft.AspNetCore.Hosting; +[Obsolete("WebHost is obsolete. Use Host.CreateDefaultBuilder or WebApplication.CreateBuilder instead.")] internal sealed partial class WebHost : IWebHost, IAsyncDisposable { private const string DeprecatedServerUrlsKey = "server.urls"; diff --git a/src/Hosting/Hosting/src/WebHostExtensions.cs b/src/Hosting/Hosting/src/WebHostExtensions.cs index 41c8e385d141..d2912b1f7b42 100644 --- a/src/Hosting/Hosting/src/WebHostExtensions.cs +++ b/src/Hosting/Hosting/src/WebHostExtensions.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Hosting; /// /// Contains extensions for managing the lifecycle of an . /// +[Obsolete("WebHostExtensions is obsolete. Use Host.CreateDefaultBuilder or WebApplication.CreateBuilder instead.")] public static class WebHostExtensions { /// diff --git a/src/Hosting/Hosting/test/Fakes/GenericWebHost.cs b/src/Hosting/Hosting/test/Fakes/GenericWebHost.cs index 1d6cd64871f4..2d3c97573d49 100644 --- a/src/Hosting/Hosting/test/Fakes/GenericWebHost.cs +++ b/src/Hosting/Hosting/test/Fakes/GenericWebHost.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Hosting/Hosting/test/Fakes/GenericWebHostBuilderWrapper.cs b/src/Hosting/Hosting/test/Fakes/GenericWebHostBuilderWrapper.cs index 57f51e921138..73642e12d29c 100644 --- a/src/Hosting/Hosting/test/Fakes/GenericWebHostBuilderWrapper.cs +++ b/src/Hosting/Hosting/test/Fakes/GenericWebHostBuilderWrapper.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Infrastructure; using Microsoft.Extensions.Configuration; diff --git a/src/Hosting/Hosting/test/WebHostTests.cs b/src/Hosting/Hosting/test/WebHostTests.cs index 36bb6a960e77..53358dc3662b 100644 --- a/src/Hosting/Hosting/test/WebHostTests.cs +++ b/src/Hosting/Hosting/test/WebHostTests.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using System.Collections; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Fakes; @@ -1085,7 +1087,9 @@ public void ConfigureServices(IServiceCollection services, int gunk) { } public void Configure(IApplicationBuilder app) { } } +#pragma warning disable CS0618 // Type or member is obsolete private IWebHost CreateHost(RequestDelegate requestDelegate) +#pragma warning restore CS0618 // Type or member is obsolete { var builder = CreateBuilder() .UseFakeServer() diff --git a/src/Hosting/TestHost/src/TestServer.cs b/src/Hosting/TestHost/src/TestServer.cs index 1c9c295406ee..de16709549bf 100644 --- a/src/Hosting/TestHost/src/TestServer.cs +++ b/src/Hosting/TestHost/src/TestServer.cs @@ -16,6 +16,7 @@ namespace Microsoft.AspNetCore.TestHost; /// public class TestServer : IServer { +#pragma warning disable CS0618 // Type or member is obsolete private readonly IWebHost? _hostInstance; private bool _disposed; private ApplicationWrapper? _application; @@ -117,6 +118,7 @@ public IWebHost Host ?? throw new InvalidOperationException("The TestServer constructor was not called with a IWebHostBuilder so IWebHost is not available."); } } +#pragma warning restore CS0618 // Type or member is obsolete /// /// Gets the service provider associated with the test server. diff --git a/src/Hosting/TestHost/src/WebHostBuilderExtensions.cs b/src/Hosting/TestHost/src/WebHostBuilderExtensions.cs index cbdb7e06e989..ba4bec0b11f2 100644 --- a/src/Hosting/TestHost/src/WebHostBuilderExtensions.cs +++ b/src/Hosting/TestHost/src/WebHostBuilderExtensions.cs @@ -14,6 +14,7 @@ namespace Microsoft.AspNetCore.TestHost; /// /// Contains extensions for configuring the instance. /// +#pragma warning disable CS0618 // Type or member is obsolete public static class WebHostBuilderExtensions { /// @@ -208,3 +209,4 @@ public Action ConfigureContainer(Action next) => }; } } +#pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/Hosting/TestHost/test/ClientHandlerTests.cs b/src/Hosting/TestHost/test/ClientHandlerTests.cs index 170310ec275a..f34422804d4e 100644 --- a/src/Hosting/TestHost/test/ClientHandlerTests.cs +++ b/src/Hosting/TestHost/test/ClientHandlerTests.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using System.Net; using System.Net.Http; using System.Text; diff --git a/src/Hosting/TestHost/test/HttpContextBuilderTests.cs b/src/Hosting/TestHost/test/HttpContextBuilderTests.cs index b46b2292339f..8ffb9fce44bc 100644 --- a/src/Hosting/TestHost/test/HttpContextBuilderTests.cs +++ b/src/Hosting/TestHost/test/HttpContextBuilderTests.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using System.Text; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; diff --git a/src/Hosting/TestHost/test/TestClientTests.cs b/src/Hosting/TestHost/test/TestClientTests.cs index 2993c53e9aa6..05bf53d9524e 100644 --- a/src/Hosting/TestHost/test/TestClientTests.cs +++ b/src/Hosting/TestHost/test/TestClientTests.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using System.Net; using System.Net.Http; using System.Net.WebSockets; diff --git a/src/Hosting/WindowsServices/src/WebHostService.cs b/src/Hosting/WindowsServices/src/WebHostService.cs index 89b9e72a2a4c..d850f8b68996 100644 --- a/src/Hosting/WindowsServices/src/WebHostService.cs +++ b/src/Hosting/WindowsServices/src/WebHostService.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Hosting.WindowsServices; /// Provides an implementation of a Windows service that hosts ASP.NET Core. /// [DesignerCategory("Code")] +[Obsolete("Use UseWindowsService and AddHostedService instead.")] public class WebHostService : ServiceBase { private readonly IWebHost _host; diff --git a/src/Hosting/WindowsServices/src/WebHostWindowsServiceExtensions.cs b/src/Hosting/WindowsServices/src/WebHostWindowsServiceExtensions.cs index 950dd27b9f4a..345a7dfadbee 100644 --- a/src/Hosting/WindowsServices/src/WebHostWindowsServiceExtensions.cs +++ b/src/Hosting/WindowsServices/src/WebHostWindowsServiceExtensions.cs @@ -8,6 +8,7 @@ namespace Microsoft.AspNetCore.Hosting.WindowsServices; /// /// Extensions to for hosting inside a Windows service. /// +[Obsolete("Use UseWindowsService and AddHostedService instead.")] public static class WebHostWindowsServiceExtensions { /// diff --git a/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs b/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs index 926ab9bcf9b5..5e8d76efc5d1 100644 --- a/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs +++ b/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs @@ -23,6 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Testing; /// /// A type in the entry point assembly of the application. /// Typically the Startup or Program classes can be used. +#pragma warning disable CS0618 // Type or member is obsolete public partial class WebApplicationFactory : IDisposable, IAsyncDisposable where TEntryPoint : class { private bool _disposed; @@ -878,3 +879,4 @@ internal override WebApplicationFactory WithWebHostBuilderCore(Acti } } } +#pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/Security/Authentication/samples/SocialSample/Program.cs b/src/Security/Authentication/samples/SocialSample/Program.cs index bd5ef8aaef63..6ea08e2eb673 100644 --- a/src/Security/Authentication/samples/SocialSample/Program.cs +++ b/src/Security/Authentication/samples/SocialSample/Program.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.AspNetCore; +using Microsoft.Extensions.Hosting; namespace SocialSample; @@ -9,8 +9,11 @@ public static class Program { public static void Main(string[] args) { - var host = WebHost.CreateDefaultBuilder(args) - .UseStartup() + var host = Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) .Build(); host.Run(); diff --git a/src/Security/samples/ClaimsTransformation/Program.cs b/src/Security/samples/ClaimsTransformation/Program.cs index baae17098bd5..0558a7a4fa93 100644 --- a/src/Security/samples/ClaimsTransformation/Program.cs +++ b/src/Security/samples/ClaimsTransformation/Program.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace AuthSamples.ClaimsTransformer; @@ -17,12 +17,15 @@ public class Program { public static void Main(string[] args) { - CreateWebHostBuilder(args) + CreateHostBuilder(args) .Build() .Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } diff --git a/src/Security/samples/Cookies/Program.cs b/src/Security/samples/Cookies/Program.cs index 240ddd39b220..a9f09625f97c 100644 --- a/src/Security/samples/Cookies/Program.cs +++ b/src/Security/samples/Cookies/Program.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace AuthSamples.Cookies; @@ -17,12 +17,15 @@ public class Program { public static void Main(string[] args) { - CreateWebHostBuilder(args) + CreateHostBuilder(args) .Build() .Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } diff --git a/src/Security/samples/CustomPolicyProvider/Program.cs b/src/Security/samples/CustomPolicyProvider/Program.cs index 10f33513900e..0065f0a3c09e 100644 --- a/src/Security/samples/CustomPolicyProvider/Program.cs +++ b/src/Security/samples/CustomPolicyProvider/Program.cs @@ -1,8 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; namespace CustomPolicyProvider; @@ -10,10 +10,13 @@ public class Program { public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + CreateHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } diff --git a/src/Security/samples/DynamicSchemes/Program.cs b/src/Security/samples/DynamicSchemes/Program.cs index 00d316db6003..adc9fad08bec 100644 --- a/src/Security/samples/DynamicSchemes/Program.cs +++ b/src/Security/samples/DynamicSchemes/Program.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace AuthSamples.DynamicSchemes; @@ -17,12 +17,15 @@ public class Program { public static void Main(string[] args) { - CreateWebHostBuilder(args) + CreateHostBuilder(args) .Build() .Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } diff --git a/src/Security/samples/Identity.ExternalClaims/Program.cs b/src/Security/samples/Identity.ExternalClaims/Program.cs index 76c69844b73e..29eecc68e7cf 100644 --- a/src/Security/samples/Identity.ExternalClaims/Program.cs +++ b/src/Security/samples/Identity.ExternalClaims/Program.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace Identity.ExternalClaims; @@ -17,10 +17,13 @@ public class Program { public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + CreateHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } diff --git a/src/Security/samples/PathSchemeSelection/Program.cs b/src/Security/samples/PathSchemeSelection/Program.cs index 03721b631e82..af44ce8957b2 100644 --- a/src/Security/samples/PathSchemeSelection/Program.cs +++ b/src/Security/samples/PathSchemeSelection/Program.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace AuthSamples.PathSchemeSelection; @@ -17,10 +17,13 @@ public class Program { public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + CreateHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } diff --git a/src/Security/samples/StaticFilesAuth/Program.cs b/src/Security/samples/StaticFilesAuth/Program.cs index 822a376c55d5..d0183d9aa6d6 100644 --- a/src/Security/samples/StaticFilesAuth/Program.cs +++ b/src/Security/samples/StaticFilesAuth/Program.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace StaticFilesAuth; @@ -17,10 +17,13 @@ public class Program { public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + CreateHostBuilder(args).Build().Run(); } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); } diff --git a/src/Servers/Kestrel/shared/test/TransportTestHelpers/IWebHostPortExtensions.cs b/src/Servers/Kestrel/shared/test/TransportTestHelpers/IWebHostPortExtensions.cs index c2774908200c..19b8ed4387e1 100644 --- a/src/Servers/Kestrel/shared/test/TransportTestHelpers/IWebHostPortExtensions.cs +++ b/src/Servers/Kestrel/shared/test/TransportTestHelpers/IWebHostPortExtensions.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +#pragma warning disable CS0618 // Type or member is obsolete + using System; using System.Collections.Generic; using System.Linq;