From fe490ab30e68ee222c01f3d4f546245f8bdd6aab Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 24 Jun 2019 10:50:11 -0700 Subject: [PATCH 1/2] Remove Hosting.Internal APIs #11312 --- ...Core.Hosting.Abstractions.netcoreapp3.0.cs | 21 ++- .../IStartupConfigureContainerFilter.cs | 5 +- .../IStartupConfigureServicesFilter.cs | 5 +- ...rosoft.AspNetCore.Hosting.netcoreapp3.0.cs | 132 ------------------ .../GenericWebHostApplicationLifetime.cs | 2 +- .../src/GenericHost/GenericWebHostBuilder.cs | 2 +- .../GenericWebHostServiceOptions.cs | 4 +- .../GenericHost/GenericWebHostedService.cs | 2 +- .../HostingStartupWebHostBuilder.cs | 4 +- .../src/GenericHost/ISupportsStartup.cs | 4 +- .../ISupportsUseDefaultServiceProvider.cs | 4 +- .../GenericHostWebHostBuilderExtensions.cs | 3 +- .../src/Internal/ActivityExtensions.cs | 8 +- .../src/Internal/ApplicationLifetime.cs | 4 +- .../Hosting/src/Internal/ConfigureBuilder.cs | 5 +- .../src/Internal/ConfigureContainerBuilder.cs | 4 +- .../src/Internal/ConfigureServicesBuilder.cs | 4 +- .../src/Internal/HostedServiceExecutor.cs | 4 +- .../src/Internal/HostingApplication.cs | 6 +- .../Internal/HostingApplicationDiagnostics.cs | 2 +- .../src/Internal/HostingEnvironment.cs | 4 +- .../Internal/HostingEnvironmentExtensions.cs | 8 +- .../src/Internal/HostingEventSource.cs | 4 +- .../src/Internal/HostingLoggerExtensions.cs | 2 +- .../src/Internal/HostingRequestFinishedLog.cs | 4 +- .../src/Internal/HostingRequestStartingLog.cs | 2 +- .../Hosting/src/Internal/LoggerEventIds.cs | 2 +- .../src/Internal/MethodInfoExtensions.cs | 2 +- .../Internal/ServiceCollectionExtensions.cs | 4 +- .../Hosting/src/Internal/StartupLoader.cs | 10 +- .../Hosting/src/Internal/StartupMethods.cs | 6 +- src/Hosting/Hosting/src/Internal/WebHost.cs | 2 +- .../Hosting/src/Internal/WebHostLifetime.cs | 2 +- .../Hosting/src/Internal/WebHostOptions.cs | 6 +- .../Hosting/src/Internal/WebHostUtilities.cs | 6 +- .../src/Microsoft.AspNetCore.Hosting.csproj | 4 + .../src/Startup/ConventionBasedStartup.cs | 4 +- src/Hosting/Hosting/src/WebHostBuilder.cs | 1 - .../Hosting/src/WebHostBuilderExtensions.cs | 1 - src/Hosting/Hosting/src/WebHostExtensions.cs | 1 - .../Hosting/test/ConfigureBuilderTests.cs | 1 - .../Fakes/GenericWebHostBuilderWrapper.cs | 3 +- .../Hosting/test/HostingApplicationTests.cs | 1 - .../test/HostingEnvironmentExtensionsTests.cs | 1 - .../test/Internal/HostingEventSourceTests.cs | 2 +- .../Internal/HostingRequestStartLogTests.cs | 10 +- .../Hosting/test/StartupManagerTests.cs | 20 ++- .../StaticWebAssetsLoaderTests.cs | 1 - .../Hosting/test/WebHostBuilderTests.cs | 1 - .../test/WebHostConfigurationsTests.cs | 1 - .../TestHost/src/ApplicationWrapper.cs | 62 ++++++++ src/Hosting/TestHost/src/ClientHandler.cs | 5 +- .../TestHost/src/HttpContextBuilder.cs | 9 +- src/Hosting/TestHost/src/TestServer.cs | 36 +---- .../TestHost/src/WebHostBuilderExtensions.cs | 9 +- src/Hosting/TestHost/src/WebSocketClient.cs | 6 +- .../TestHost/test/ClientHandlerTests.cs | 51 +++++-- .../test/KestrelConfigurationBuilderTests.cs | 13 +- 58 files changed, 242 insertions(+), 290 deletions(-) rename src/Hosting/Abstractions/src/{Internal => }/IStartupConfigureContainerFilter.cs (82%) rename src/Hosting/Abstractions/src/{Internal => }/IStartupConfigureServicesFilter.cs (83%) create mode 100644 src/Hosting/TestHost/src/ApplicationWrapper.cs diff --git a/src/Hosting/Abstractions/ref/Microsoft.AspNetCore.Hosting.Abstractions.netcoreapp3.0.cs b/src/Hosting/Abstractions/ref/Microsoft.AspNetCore.Hosting.Abstractions.netcoreapp3.0.cs index 9d856ad0ed10..0da29eccab17 100644 --- a/src/Hosting/Abstractions/ref/Microsoft.AspNetCore.Hosting.Abstractions.netcoreapp3.0.cs +++ b/src/Hosting/Abstractions/ref/Microsoft.AspNetCore.Hosting.Abstractions.netcoreapp3.0.cs @@ -65,6 +65,16 @@ public partial interface IStartup void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app); System.IServiceProvider ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services); } + [System.ObsoleteAttribute] + public partial interface IStartupConfigureContainerFilter + { + System.Action ConfigureContainer(System.Action container); + } + [System.ObsoleteAttribute] + public partial interface IStartupConfigureServicesFilter + { + System.Action ConfigureServices(System.Action next); + } public partial interface IStartupFilter { System.Action Configure(System.Action next); @@ -115,14 +125,3 @@ public static partial class WebHostDefaults public static readonly string WebRootKey; } } -namespace Microsoft.AspNetCore.Hosting.Internal -{ - public partial interface IStartupConfigureContainerFilter - { - System.Action ConfigureContainer(System.Action container); - } - public partial interface IStartupConfigureServicesFilter - { - System.Action ConfigureServices(System.Action next); - } -} diff --git a/src/Hosting/Abstractions/src/Internal/IStartupConfigureContainerFilter.cs b/src/Hosting/Abstractions/src/IStartupConfigureContainerFilter.cs similarity index 82% rename from src/Hosting/Abstractions/src/Internal/IStartupConfigureContainerFilter.cs rename to src/Hosting/Abstractions/src/IStartupConfigureContainerFilter.cs index e58ac19774de..48c0dbd80fc1 100644 --- a/src/Hosting/Abstractions/src/Internal/IStartupConfigureContainerFilter.cs +++ b/src/Hosting/Abstractions/src/IStartupConfigureContainerFilter.cs @@ -1,14 +1,15 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { /// /// This API supports the ASP.NET Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// + [Obsolete] public interface IStartupConfigureContainerFilter { Action ConfigureContainer(Action container); diff --git a/src/Hosting/Abstractions/src/Internal/IStartupConfigureServicesFilter.cs b/src/Hosting/Abstractions/src/IStartupConfigureServicesFilter.cs similarity index 83% rename from src/Hosting/Abstractions/src/Internal/IStartupConfigureServicesFilter.cs rename to src/Hosting/Abstractions/src/IStartupConfigureServicesFilter.cs index ad203bcedb60..8594b1c3f1c8 100644 --- a/src/Hosting/Abstractions/src/Internal/IStartupConfigureServicesFilter.cs +++ b/src/Hosting/Abstractions/src/IStartupConfigureServicesFilter.cs @@ -1,15 +1,16 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { /// /// This API supports the ASP.NET Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// + [Obsolete] public interface IStartupConfigureServicesFilter { Action ConfigureServices(Action next); diff --git a/src/Hosting/Hosting/ref/Microsoft.AspNetCore.Hosting.netcoreapp3.0.cs b/src/Hosting/Hosting/ref/Microsoft.AspNetCore.Hosting.netcoreapp3.0.cs index a98b00df2996..d2cfa3332738 100644 --- a/src/Hosting/Hosting/ref/Microsoft.AspNetCore.Hosting.netcoreapp3.0.cs +++ b/src/Hosting/Hosting/ref/Microsoft.AspNetCore.Hosting.netcoreapp3.0.cs @@ -71,138 +71,6 @@ public partial interface IApplicationBuilderFactory Microsoft.AspNetCore.Builder.IApplicationBuilder CreateBuilder(Microsoft.AspNetCore.Http.Features.IFeatureCollection serverFeatures); } } -namespace Microsoft.AspNetCore.Hosting.Internal -{ - public partial class ApplicationLifetime : Microsoft.AspNetCore.Hosting.IApplicationLifetime, Microsoft.Extensions.Hosting.IApplicationLifetime, Microsoft.Extensions.Hosting.IHostApplicationLifetime - { - public ApplicationLifetime(Microsoft.Extensions.Logging.ILogger logger) { } - public System.Threading.CancellationToken ApplicationStarted { get { throw null; } } - public System.Threading.CancellationToken ApplicationStopped { get { throw null; } } - public System.Threading.CancellationToken ApplicationStopping { get { throw null; } } - public void NotifyStarted() { } - public void NotifyStopped() { } - public void StopApplication() { } - } - public partial class ConfigureBuilder - { - public ConfigureBuilder(System.Reflection.MethodInfo configure) { } - public System.Reflection.MethodInfo MethodInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } - public System.Action Build(object instance) { throw null; } - } - public partial class ConfigureContainerBuilder - { - public ConfigureContainerBuilder(System.Reflection.MethodInfo configureContainerMethod) { } - public System.Func, System.Action> ConfigureContainerFilters { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public System.Reflection.MethodInfo MethodInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } - public System.Action Build(object instance) { throw null; } - public System.Type GetContainerType() { throw null; } - } - public partial class ConfigureServicesBuilder - { - public ConfigureServicesBuilder(System.Reflection.MethodInfo configureServices) { } - public System.Reflection.MethodInfo MethodInfo { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } - public System.Func, System.Func> StartupServiceFilters { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public System.Func Build(object instance) { throw null; } - } - public partial class ConventionBasedStartup : Microsoft.AspNetCore.Hosting.IStartup - { - public ConventionBasedStartup(Microsoft.AspNetCore.Hosting.Internal.StartupMethods methods) { } - public void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app) { } - public System.IServiceProvider ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services) { throw null; } - } - public partial class HostedServiceExecutor - { - public HostedServiceExecutor(Microsoft.Extensions.Logging.ILogger logger, System.Collections.Generic.IEnumerable services) { } - public System.Threading.Tasks.Task StartAsync(System.Threading.CancellationToken token) { throw null; } - public System.Threading.Tasks.Task StopAsync(System.Threading.CancellationToken token) { throw null; } - } - public partial class HostingApplication : Microsoft.AspNetCore.Hosting.Server.IHttpApplication - { - public HostingApplication(Microsoft.AspNetCore.Http.RequestDelegate application, Microsoft.Extensions.Logging.ILogger logger, System.Diagnostics.DiagnosticListener diagnosticSource, Microsoft.AspNetCore.Http.IHttpContextFactory httpContextFactory) { } - public Microsoft.AspNetCore.Hosting.Internal.HostingApplication.Context CreateContext(Microsoft.AspNetCore.Http.Features.IFeatureCollection contextFeatures) { throw null; } - public void DisposeContext(Microsoft.AspNetCore.Hosting.Internal.HostingApplication.Context context, System.Exception exception) { } - public System.Threading.Tasks.Task ProcessRequestAsync(Microsoft.AspNetCore.Hosting.Internal.HostingApplication.Context context) { throw null; } - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct Context - { - private object _dummy; - private int _dummyPrimitive; - public System.Diagnostics.Activity Activity { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public bool EventLogEnabled { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public Microsoft.AspNetCore.Http.HttpContext HttpContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public System.IDisposable Scope { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public long StartTimestamp { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - } - } - public partial class HostingEnvironment : Microsoft.AspNetCore.Hosting.IHostingEnvironment, Microsoft.AspNetCore.Hosting.IWebHostEnvironment, Microsoft.Extensions.Hosting.IHostEnvironment, Microsoft.Extensions.Hosting.IHostingEnvironment - { - public HostingEnvironment() { } - public string ApplicationName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public Microsoft.Extensions.FileProviders.IFileProvider ContentRootFileProvider { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public string ContentRootPath { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public string EnvironmentName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public Microsoft.Extensions.FileProviders.IFileProvider WebRootFileProvider { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public string WebRootPath { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - } - public static partial class HostingEnvironmentExtensions - { - public static void Initialize(this Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, string contentRootPath, Microsoft.AspNetCore.Hosting.Internal.WebHostOptions options) { } - public static void Initialize(this Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment, string contentRootPath, Microsoft.AspNetCore.Hosting.Internal.WebHostOptions options) { } - } - public sealed partial class HostingEventSource : System.Diagnostics.Tracing.EventSource - { - internal HostingEventSource() { } - public static readonly Microsoft.AspNetCore.Hosting.Internal.HostingEventSource Log; - [System.Diagnostics.Tracing.EventAttribute(1, Level=System.Diagnostics.Tracing.EventLevel.Informational)] - public void HostStart() { } - [System.Diagnostics.Tracing.EventAttribute(2, Level=System.Diagnostics.Tracing.EventLevel.Informational)] - public void HostStop() { } - protected override void OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs command) { } - [System.Diagnostics.Tracing.EventAttribute(3, Level=System.Diagnostics.Tracing.EventLevel.Informational)] - public void RequestStart(string method, string path) { } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)][System.Diagnostics.Tracing.EventAttribute(4, Level=System.Diagnostics.Tracing.EventLevel.Informational)] - public void RequestStop() { } - [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)][System.Diagnostics.Tracing.EventAttribute(5, Level=System.Diagnostics.Tracing.EventLevel.Error)] - public void UnhandledException() { } - } - public partial class StartupLoader - { - public StartupLoader() { } - public static System.Type FindStartupType(string startupAssemblyName, string environmentName) { throw null; } - public static Microsoft.AspNetCore.Hosting.Internal.StartupMethods LoadMethods(System.IServiceProvider hostingServiceProvider, System.Type startupType, string environmentName) { throw null; } - } - public partial class StartupMethods - { - public StartupMethods(object instance, System.Action configure, System.Func configureServices) { } - public System.Action ConfigureDelegate { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } - public System.Func ConfigureServicesDelegate { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } - public object StartupInstance { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } - } - public partial class WebHostOptions - { - public WebHostOptions() { } - public WebHostOptions(Microsoft.Extensions.Configuration.IConfiguration configuration) { } - public WebHostOptions(Microsoft.Extensions.Configuration.IConfiguration configuration, string applicationNameFallback) { } - public string ApplicationName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public bool CaptureStartupErrors { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public string ContentRootPath { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public bool DetailedErrors { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public string Environment { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public System.Collections.Generic.IReadOnlyList HostingStartupAssemblies { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public System.Collections.Generic.IReadOnlyList HostingStartupExcludeAssemblies { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public bool PreventHostingStartup { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public System.TimeSpan ShutdownTimeout { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public string StartupAssembly { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public bool SuppressStatusMessages { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public string WebRoot { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - public System.Collections.Generic.IEnumerable GetFinalHostingStartupAssemblies() { throw null; } - } - public partial class WebHostUtilities - { - public WebHostUtilities() { } - public static bool ParseBool(Microsoft.Extensions.Configuration.IConfiguration configuration, string key) { throw null; } - } -} namespace Microsoft.AspNetCore.Hosting.Server.Features { public partial class ServerAddressesFeature : Microsoft.AspNetCore.Hosting.Server.Features.IServerAddressesFeature diff --git a/src/Hosting/Hosting/src/GenericHost/GenericWebHostApplicationLifetime.cs b/src/Hosting/Hosting/src/GenericHost/GenericWebHostApplicationLifetime.cs index 1fbb66771b53..d1609fe77160 100644 --- a/src/Hosting/Hosting/src/GenericHost/GenericWebHostApplicationLifetime.cs +++ b/src/Hosting/Hosting/src/GenericHost/GenericWebHostApplicationLifetime.cs @@ -4,7 +4,7 @@ using System.Threading; using Microsoft.Extensions.Hosting; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { #pragma warning disable CS0618 // Type or member is obsolete internal class GenericWebHostApplicationLifetime : IApplicationLifetime diff --git a/src/Hosting/Hosting/src/GenericHost/GenericWebHostBuilder.cs b/src/Hosting/Hosting/src/GenericHost/GenericWebHostBuilder.cs index a42e5cbf48c5..8af0174431b6 100644 --- a/src/Hosting/Hosting/src/GenericHost/GenericWebHostBuilder.cs +++ b/src/Hosting/Hosting/src/GenericHost/GenericWebHostBuilder.cs @@ -16,7 +16,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.ObjectPool; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal class GenericWebHostBuilder : IWebHostBuilder, ISupportsStartup, ISupportsUseDefaultServiceProvider { diff --git a/src/Hosting/Hosting/src/GenericHost/GenericWebHostServiceOptions.cs b/src/Hosting/Hosting/src/GenericHost/GenericWebHostServiceOptions.cs index 715c43514e1c..3155c824dd93 100644 --- a/src/Hosting/Hosting/src/GenericHost/GenericWebHostServiceOptions.cs +++ b/src/Hosting/Hosting/src/GenericHost/GenericWebHostServiceOptions.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNetCore.Builder; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal class GenericWebHostServiceOptions { diff --git a/src/Hosting/Hosting/src/GenericHost/GenericWebHostedService.cs b/src/Hosting/Hosting/src/GenericHost/GenericWebHostedService.cs index 225ae6c6efe3..5d7070fce860 100644 --- a/src/Hosting/Hosting/src/GenericHost/GenericWebHostedService.cs +++ b/src/Hosting/Hosting/src/GenericHost/GenericWebHostedService.cs @@ -22,7 +22,7 @@ using Microsoft.Extensions.StackTrace.Sources; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal class GenericWebHostService : IHostedService { diff --git a/src/Hosting/Hosting/src/GenericHost/HostingStartupWebHostBuilder.cs b/src/Hosting/Hosting/src/GenericHost/HostingStartupWebHostBuilder.cs index 65c096e965c4..42cda1cc81f9 100644 --- a/src/Hosting/Hosting/src/GenericHost/HostingStartupWebHostBuilder.cs +++ b/src/Hosting/Hosting/src/GenericHost/HostingStartupWebHostBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,7 +6,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { // We use this type to capture calls to the IWebHostBuilder so the we can properly order calls to // to GenericHostWebHostBuilder. diff --git a/src/Hosting/Hosting/src/GenericHost/ISupportsStartup.cs b/src/Hosting/Hosting/src/GenericHost/ISupportsStartup.cs index 0f3be6b20914..8a2d1dd8abd5 100644 --- a/src/Hosting/Hosting/src/GenericHost/ISupportsStartup.cs +++ b/src/Hosting/Hosting/src/GenericHost/ISupportsStartup.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNetCore.Builder; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal interface ISupportsStartup { diff --git a/src/Hosting/Hosting/src/GenericHost/ISupportsUseDefaultServiceProvider.cs b/src/Hosting/Hosting/src/GenericHost/ISupportsUseDefaultServiceProvider.cs index bf9813cd6e47..4500e9408fce 100644 --- a/src/Hosting/Hosting/src/GenericHost/ISupportsUseDefaultServiceProvider.cs +++ b/src/Hosting/Hosting/src/GenericHost/ISupportsUseDefaultServiceProvider.cs @@ -1,10 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal interface ISupportsUseDefaultServiceProvider { diff --git a/src/Hosting/Hosting/src/GenericHostWebHostBuilderExtensions.cs b/src/Hosting/Hosting/src/GenericHostWebHostBuilderExtensions.cs index ea903ad7b598..e2610777f0b3 100644 --- a/src/Hosting/Hosting/src/GenericHostWebHostBuilderExtensions.cs +++ b/src/Hosting/Hosting/src/GenericHostWebHostBuilderExtensions.cs @@ -1,6 +1,5 @@ -using System; +using System; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Internal; namespace Microsoft.Extensions.Hosting { diff --git a/src/Hosting/Hosting/src/Internal/ActivityExtensions.cs b/src/Hosting/Hosting/src/Internal/ActivityExtensions.cs index 0391346cf97b..fa23a5ca12b0 100644 --- a/src/Hosting/Hosting/src/Internal/ActivityExtensions.cs +++ b/src/Hosting/Hosting/src/Internal/ActivityExtensions.cs @@ -1,9 +1,9 @@ -using System; -using System.Collections.Generic; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using System.Diagnostics; -using System.Text; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { /// /// Helpers for getting the right values from Activity no matter the format (w3c or hierarchical) diff --git a/src/Hosting/Hosting/src/Internal/ApplicationLifetime.cs b/src/Hosting/Hosting/src/Internal/ApplicationLifetime.cs index ac19e8b05261..20fdaf428686 100644 --- a/src/Hosting/Hosting/src/Internal/ApplicationLifetime.cs +++ b/src/Hosting/Hosting/src/Internal/ApplicationLifetime.cs @@ -6,13 +6,13 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { /// /// Allows consumers to perform cleanup during a graceful shutdown. /// #pragma warning disable CS0618 // Type or member is obsolete - public class ApplicationLifetime : IApplicationLifetime, Extensions.Hosting.IApplicationLifetime, IHostApplicationLifetime + internal class ApplicationLifetime : IApplicationLifetime, Extensions.Hosting.IApplicationLifetime, IHostApplicationLifetime #pragma warning restore CS0618 // Type or member is obsolete { private readonly CancellationTokenSource _startedSource = new CancellationTokenSource(); diff --git a/src/Hosting/Hosting/src/Internal/ConfigureBuilder.cs b/src/Hosting/Hosting/src/Internal/ConfigureBuilder.cs index 0daaa0567c0b..e391acd0f3e3 100644 --- a/src/Hosting/Hosting/src/Internal/ConfigureBuilder.cs +++ b/src/Hosting/Hosting/src/Internal/ConfigureBuilder.cs @@ -2,14 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Globalization; using System.Reflection; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public class ConfigureBuilder + internal class ConfigureBuilder { public ConfigureBuilder(MethodInfo configure) { diff --git a/src/Hosting/Hosting/src/Internal/ConfigureContainerBuilder.cs b/src/Hosting/Hosting/src/Internal/ConfigureContainerBuilder.cs index c50d66b18f7a..f5ca64d7115d 100644 --- a/src/Hosting/Hosting/src/Internal/ConfigureContainerBuilder.cs +++ b/src/Hosting/Hosting/src/Internal/ConfigureContainerBuilder.cs @@ -4,9 +4,9 @@ using System; using System.Reflection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public class ConfigureContainerBuilder + internal class ConfigureContainerBuilder { public ConfigureContainerBuilder(MethodInfo configureContainerMethod) { diff --git a/src/Hosting/Hosting/src/Internal/ConfigureServicesBuilder.cs b/src/Hosting/Hosting/src/Internal/ConfigureServicesBuilder.cs index 49e07c48f81d..58ca624c9e43 100644 --- a/src/Hosting/Hosting/src/Internal/ConfigureServicesBuilder.cs +++ b/src/Hosting/Hosting/src/Internal/ConfigureServicesBuilder.cs @@ -6,9 +6,9 @@ using System.Reflection; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public class ConfigureServicesBuilder + internal class ConfigureServicesBuilder { public ConfigureServicesBuilder(MethodInfo configureServices) { diff --git a/src/Hosting/Hosting/src/Internal/HostedServiceExecutor.cs b/src/Hosting/Hosting/src/Internal/HostedServiceExecutor.cs index 131b254e3c0c..34e2a6d75f16 100644 --- a/src/Hosting/Hosting/src/Internal/HostedServiceExecutor.cs +++ b/src/Hosting/Hosting/src/Internal/HostedServiceExecutor.cs @@ -8,9 +8,9 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public class HostedServiceExecutor + internal class HostedServiceExecutor { private readonly IEnumerable _services; private readonly ILogger _logger; diff --git a/src/Hosting/Hosting/src/Internal/HostingApplication.cs b/src/Hosting/Hosting/src/Internal/HostingApplication.cs index 416c49f21888..48e846fe1047 100644 --- a/src/Hosting/Hosting/src/Internal/HostingApplication.cs +++ b/src/Hosting/Hosting/src/Internal/HostingApplication.cs @@ -9,9 +9,9 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public class HostingApplication : IHttpApplication + internal class HostingApplication : IHttpApplication { private readonly RequestDelegate _application; private readonly IHttpContextFactory _httpContextFactory; @@ -55,7 +55,7 @@ public void DisposeContext(Context context, Exception exception) _diagnostics.ContextDisposed(context); } - public struct Context + internal struct Context { public HttpContext HttpContext { get; set; } public IDisposable Scope { get; set; } diff --git a/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs b/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs index c278a867784e..e499e81e2092 100644 --- a/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs +++ b/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs @@ -9,7 +9,7 @@ using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal class HostingApplicationDiagnostics { diff --git a/src/Hosting/Hosting/src/Internal/HostingEnvironment.cs b/src/Hosting/Hosting/src/Internal/HostingEnvironment.cs index 1e894ebb1a62..6f409e41ef25 100644 --- a/src/Hosting/Hosting/src/Internal/HostingEnvironment.cs +++ b/src/Hosting/Hosting/src/Internal/HostingEnvironment.cs @@ -3,10 +3,10 @@ using Microsoft.Extensions.FileProviders; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { #pragma warning disable CS0618 // Type or member is obsolete - public class HostingEnvironment : IHostingEnvironment, Extensions.Hosting.IHostingEnvironment, IWebHostEnvironment + internal class HostingEnvironment : IHostingEnvironment, Extensions.Hosting.IHostingEnvironment, IWebHostEnvironment #pragma warning restore CS0618 // Type or member is obsolete { public string EnvironmentName { get; set; } = Extensions.Hosting.Environments.Production; diff --git a/src/Hosting/Hosting/src/Internal/HostingEnvironmentExtensions.cs b/src/Hosting/Hosting/src/Internal/HostingEnvironmentExtensions.cs index 1670aa8d09fc..2b8b316f279f 100644 --- a/src/Hosting/Hosting/src/Internal/HostingEnvironmentExtensions.cs +++ b/src/Hosting/Hosting/src/Internal/HostingEnvironmentExtensions.cs @@ -5,12 +5,12 @@ using System.IO; using Microsoft.Extensions.FileProviders; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public static class HostingEnvironmentExtensions + internal static class HostingEnvironmentExtensions { #pragma warning disable CS0618 // Type or member is obsolete - public static void Initialize(this IHostingEnvironment hostingEnvironment, string contentRootPath, WebHostOptions options) + internal static void Initialize(this IHostingEnvironment hostingEnvironment, string contentRootPath, WebHostOptions options) #pragma warning restore CS0618 // Type or member is obsolete { if (options == null) @@ -64,7 +64,7 @@ public static void Initialize(this IHostingEnvironment hostingEnvironment, strin hostingEnvironment.EnvironmentName; } - public static void Initialize(this IWebHostEnvironment hostingEnvironment, string contentRootPath, WebHostOptions options) + internal static void Initialize(this IWebHostEnvironment hostingEnvironment, string contentRootPath, WebHostOptions options) { if (options == null) { diff --git a/src/Hosting/Hosting/src/Internal/HostingEventSource.cs b/src/Hosting/Hosting/src/Internal/HostingEventSource.cs index 2b8d188373d7..6fcfa6726060 100644 --- a/src/Hosting/Hosting/src/Internal/HostingEventSource.cs +++ b/src/Hosting/Hosting/src/Internal/HostingEventSource.cs @@ -6,9 +6,9 @@ using System.Runtime.CompilerServices; using System.Threading; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public sealed class HostingEventSource : EventSource + internal sealed class HostingEventSource : EventSource { public static readonly HostingEventSource Log = new HostingEventSource(); diff --git a/src/Hosting/Hosting/src/Internal/HostingLoggerExtensions.cs b/src/Hosting/Hosting/src/Internal/HostingLoggerExtensions.cs index 72140480ab39..e5fb4fd0c6e6 100644 --- a/src/Hosting/Hosting/src/Internal/HostingLoggerExtensions.cs +++ b/src/Hosting/Hosting/src/Internal/HostingLoggerExtensions.cs @@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal static class HostingLoggerExtensions { diff --git a/src/Hosting/Hosting/src/Internal/HostingRequestFinishedLog.cs b/src/Hosting/Hosting/src/Internal/HostingRequestFinishedLog.cs index ab440481bae7..63fd5f0921ea 100644 --- a/src/Hosting/Hosting/src/Internal/HostingRequestFinishedLog.cs +++ b/src/Hosting/Hosting/src/Internal/HostingRequestFinishedLog.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -7,7 +7,7 @@ using System.Globalization; using Microsoft.AspNetCore.Http; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal class HostingRequestFinishedLog : IReadOnlyList> { diff --git a/src/Hosting/Hosting/src/Internal/HostingRequestStartingLog.cs b/src/Hosting/Hosting/src/Internal/HostingRequestStartingLog.cs index 4d9901cdd69a..279fa06aed04 100644 --- a/src/Hosting/Hosting/src/Internal/HostingRequestStartingLog.cs +++ b/src/Hosting/Hosting/src/Internal/HostingRequestStartingLog.cs @@ -7,7 +7,7 @@ using System.Globalization; using Microsoft.AspNetCore.Http; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal class HostingRequestStartingLog : IReadOnlyList> { diff --git a/src/Hosting/Hosting/src/Internal/LoggerEventIds.cs b/src/Hosting/Hosting/src/Internal/LoggerEventIds.cs index f7d8f61933a8..a7c75fafdc06 100644 --- a/src/Hosting/Hosting/src/Internal/LoggerEventIds.cs +++ b/src/Hosting/Hosting/src/Internal/LoggerEventIds.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal static class LoggerEventIds { diff --git a/src/Hosting/Hosting/src/Internal/MethodInfoExtensions.cs b/src/Hosting/Hosting/src/Internal/MethodInfoExtensions.cs index fe9b7690af17..0654839696be 100644 --- a/src/Hosting/Hosting/src/Internal/MethodInfoExtensions.cs +++ b/src/Hosting/Hosting/src/Internal/MethodInfoExtensions.cs @@ -3,7 +3,7 @@ using System.Reflection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal static class MethodInfoExtensions { diff --git a/src/Hosting/Hosting/src/Internal/ServiceCollectionExtensions.cs b/src/Hosting/Hosting/src/Internal/ServiceCollectionExtensions.cs index 48b8758181e4..fca61bc4b14d 100644 --- a/src/Hosting/Hosting/src/Internal/ServiceCollectionExtensions.cs +++ b/src/Hosting/Hosting/src/Internal/ServiceCollectionExtensions.cs @@ -1,9 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal static class ServiceCollectionExtensions { diff --git a/src/Hosting/Hosting/src/Internal/StartupLoader.cs b/src/Hosting/Hosting/src/Internal/StartupLoader.cs index e4121da4fb0a..46c195c22a1e 100644 --- a/src/Hosting/Hosting/src/Internal/StartupLoader.cs +++ b/src/Hosting/Hosting/src/Internal/StartupLoader.cs @@ -8,9 +8,9 @@ using System.Reflection; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public class StartupLoader + internal class StartupLoader { // Creates an instance with the actions to run for configuring the application services and the // request pipeline of the application. @@ -157,7 +157,9 @@ private Func BuildStartupServicesFilterPip IServiceProvider RunPipeline(IServiceCollection services) { +#pragma warning disable CS0612 // Type or member is obsolete var filters = HostingServiceProvider.GetRequiredService>().Reverse().ToArray(); +#pragma warning restore CS0612 // Type or member is obsolete // If there are no filters just run startup (makes IServiceProvider ConfigureServices(IServiceCollection services) work. if (filters.Length == 0) @@ -182,9 +184,11 @@ void InvokeStartup(IServiceCollection serviceCollection) if (filters.Length > 0 && result != null) { // public IServiceProvider ConfigureServices(IServiceCollection serviceCollection) is not compatible with IStartupServicesFilter; +#pragma warning disable CS0612 // Type or member is obsolete var message = $"A ConfigureServices method that returns an {nameof(IServiceProvider)} is " + $"not compatible with the use of one or more {nameof(IStartupConfigureServicesFilter)}. " + $"Use a void returning ConfigureServices method instead or a ConfigureContainer method."; +#pragma warning restore CS0612 // Type or member is obsolete throw new InvalidOperationException(message); }; } @@ -198,7 +202,9 @@ private Action BuildStartupConfigureContainerFiltersPipeline( void RunPipeline(TContainerBuilder containerBuilder) { var filters = HostingServiceProvider +#pragma warning disable CS0612 // Type or member is obsolete .GetRequiredService>>() +#pragma warning restore CS0612 // Type or member is obsolete .Reverse() .ToArray(); diff --git a/src/Hosting/Hosting/src/Internal/StartupMethods.cs b/src/Hosting/Hosting/src/Internal/StartupMethods.cs index f854c859465c..54f1d4d58c6c 100644 --- a/src/Hosting/Hosting/src/Internal/StartupMethods.cs +++ b/src/Hosting/Hosting/src/Internal/StartupMethods.cs @@ -6,9 +6,9 @@ using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public class StartupMethods + internal class StartupMethods { public StartupMethods(object instance, Action configure, Func configureServices) { @@ -25,4 +25,4 @@ public StartupMethods(object instance, Action configure, Fu public Action ConfigureDelegate { get; } } -} \ No newline at end of file +} diff --git a/src/Hosting/Hosting/src/Internal/WebHost.cs b/src/Hosting/Hosting/src/Internal/WebHost.cs index 57b974a80002..504f1d28317b 100644 --- a/src/Hosting/Hosting/src/Internal/WebHost.cs +++ b/src/Hosting/Hosting/src/Internal/WebHost.cs @@ -25,7 +25,7 @@ using Microsoft.Extensions.StackTrace.Sources; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal class WebHost : IWebHost, IAsyncDisposable { diff --git a/src/Hosting/Hosting/src/Internal/WebHostLifetime.cs b/src/Hosting/Hosting/src/Internal/WebHostLifetime.cs index ea0e631a940a..9d47fb68f5ab 100644 --- a/src/Hosting/Hosting/src/Internal/WebHostLifetime.cs +++ b/src/Hosting/Hosting/src/Internal/WebHostLifetime.cs @@ -4,7 +4,7 @@ using System; using System.Threading; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { internal class WebHostLifetime : IDisposable { diff --git a/src/Hosting/Hosting/src/Internal/WebHostOptions.cs b/src/Hosting/Hosting/src/Internal/WebHostOptions.cs index e9e611bc699b..88ceac1dacf4 100644 --- a/src/Hosting/Hosting/src/Internal/WebHostOptions.cs +++ b/src/Hosting/Hosting/src/Internal/WebHostOptions.cs @@ -7,9 +7,9 @@ using System.Linq; using Microsoft.Extensions.Configuration; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public class WebHostOptions + internal class WebHostOptions { public WebHostOptions() { } @@ -93,4 +93,4 @@ private IReadOnlyList Split(string value) return list; } } -} \ No newline at end of file +} diff --git a/src/Hosting/Hosting/src/Internal/WebHostUtilities.cs b/src/Hosting/Hosting/src/Internal/WebHostUtilities.cs index 49635699d15a..da24912337ef 100644 --- a/src/Hosting/Hosting/src/Internal/WebHostUtilities.cs +++ b/src/Hosting/Hosting/src/Internal/WebHostUtilities.cs @@ -1,12 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.Extensions.Configuration; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public class WebHostUtilities + internal class WebHostUtilities { public static bool ParseBool(IConfiguration configuration, string key) { diff --git a/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj b/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj index a90dbfb94321..3f4399d24ec6 100644 --- a/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj +++ b/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj @@ -31,4 +31,8 @@ + + + + diff --git a/src/Hosting/Hosting/src/Startup/ConventionBasedStartup.cs b/src/Hosting/Hosting/src/Startup/ConventionBasedStartup.cs index 35b19f4b1402..ce266f6f0fb1 100644 --- a/src/Hosting/Hosting/src/Startup/ConventionBasedStartup.cs +++ b/src/Hosting/Hosting/src/Startup/ConventionBasedStartup.cs @@ -7,9 +7,9 @@ using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { - public class ConventionBasedStartup : IStartup + internal class ConventionBasedStartup : IStartup { private readonly StartupMethods _methods; diff --git a/src/Hosting/Hosting/src/WebHostBuilder.cs b/src/Hosting/Hosting/src/WebHostBuilder.cs index 737eae8d67a3..f922289d465f 100644 --- a/src/Hosting/Hosting/src/WebHostBuilder.cs +++ b/src/Hosting/Hosting/src/WebHostBuilder.cs @@ -9,7 +9,6 @@ using System.Reflection; using System.Runtime.ExceptionServices; using Microsoft.AspNetCore.Hosting.Builder; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Hosting/Hosting/src/WebHostBuilderExtensions.cs b/src/Hosting/Hosting/src/WebHostBuilderExtensions.cs index f6ea1c797e82..c3979170d702 100644 --- a/src/Hosting/Hosting/src/WebHostBuilderExtensions.cs +++ b/src/Hosting/Hosting/src/WebHostBuilderExtensions.cs @@ -4,7 +4,6 @@ using System; using System.Reflection; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; diff --git a/src/Hosting/Hosting/src/WebHostExtensions.cs b/src/Hosting/Hosting/src/WebHostExtensions.cs index 9bbb39dd111c..a356f584894a 100644 --- a/src/Hosting/Hosting/src/WebHostExtensions.cs +++ b/src/Hosting/Hosting/src/WebHostExtensions.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.Hosting; namespace Microsoft.AspNetCore.Hosting diff --git a/src/Hosting/Hosting/test/ConfigureBuilderTests.cs b/src/Hosting/Hosting/test/ConfigureBuilderTests.cs index e7928b702e65..260aa7fb1bc6 100644 --- a/src/Hosting/Hosting/test/ConfigureBuilderTests.cs +++ b/src/Hosting/Hosting/test/ConfigureBuilderTests.cs @@ -4,7 +4,6 @@ using System; using System.Reflection; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.DependencyInjection; using Xunit; diff --git a/src/Hosting/Hosting/test/Fakes/GenericWebHostBuilderWrapper.cs b/src/Hosting/Hosting/test/Fakes/GenericWebHostBuilderWrapper.cs index eaa484a820e4..096a18cf77a0 100644 --- a/src/Hosting/Hosting/test/Fakes/GenericWebHostBuilderWrapper.cs +++ b/src/Hosting/Hosting/test/Fakes/GenericWebHostBuilderWrapper.cs @@ -1,9 +1,8 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; diff --git a/src/Hosting/Hosting/test/HostingApplicationTests.cs b/src/Hosting/Hosting/test/HostingApplicationTests.cs index d799d984da46..fd8680100de8 100644 --- a/src/Hosting/Hosting/test/HostingApplicationTests.cs +++ b/src/Hosting/Hosting/test/HostingApplicationTests.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; diff --git a/src/Hosting/Hosting/test/HostingEnvironmentExtensionsTests.cs b/src/Hosting/Hosting/test/HostingEnvironmentExtensionsTests.cs index c0eeffdaec45..353aaf9d418b 100644 --- a/src/Hosting/Hosting/test/HostingEnvironmentExtensionsTests.cs +++ b/src/Hosting/Hosting/test/HostingEnvironmentExtensionsTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.IO; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.FileProviders; using Xunit; diff --git a/src/Hosting/Hosting/test/Internal/HostingEventSourceTests.cs b/src/Hosting/Hosting/test/Internal/HostingEventSourceTests.cs index ce0acef6c80c..bcf4188a398c 100644 --- a/src/Hosting/Hosting/test/Internal/HostingEventSourceTests.cs +++ b/src/Hosting/Hosting/test/Internal/HostingEventSourceTests.cs @@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Testing.xunit; using Xunit; -namespace Microsoft.AspNetCore.Hosting.Internal +namespace Microsoft.AspNetCore.Hosting { public class HostingEventSourceTests { diff --git a/src/Hosting/Hosting/test/Internal/HostingRequestStartLogTests.cs b/src/Hosting/Hosting/test/Internal/HostingRequestStartLogTests.cs index ca8e25ed9e06..e2fe48b59dc3 100644 --- a/src/Hosting/Hosting/test/Internal/HostingRequestStartLogTests.cs +++ b/src/Hosting/Hosting/test/Internal/HostingRequestStartLogTests.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Text; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Hosting.Internal; using Moq; using Xunit; -namespace Microsoft.AspNetCore.Hosting.Tests.Internal + +namespace Microsoft.AspNetCore.Hosting.Tests { public class HostingRequestStartLogTests { diff --git a/src/Hosting/Hosting/test/StartupManagerTests.cs b/src/Hosting/Hosting/test/StartupManagerTests.cs index 3134b16731dd..a9562a5b8a07 100644 --- a/src/Hosting/Hosting/test/StartupManagerTests.cs +++ b/src/Hosting/Hosting/test/StartupManagerTests.cs @@ -3,10 +3,8 @@ using System; using System.Collections.Generic; -using System.Reflection; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.Fakes; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Hosting.Tests.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -23,8 +21,10 @@ public void ConventionalStartupClass_StartupServiceFilters_WrapsConfigureService { var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton, DefaultServiceProviderFactory>(); +#pragma warning disable CS0612 // Type or member is obsolete serviceCollection.AddSingleton(new TestStartupServicesFilter(1, overrideAfterService: true)); serviceCollection.AddSingleton(new TestStartupServicesFilter(2, overrideAfterService: true)); +#pragma warning restore CS0612 // Type or member is obsolete var services = serviceCollection.BuildServiceProvider(); var type = typeof(VoidReturningStartupServicesFiltersStartup); @@ -43,8 +43,10 @@ public void ConventionalStartupClass_StartupServiceFilters_MultipleStartupServic { var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton, DefaultServiceProviderFactory>(); +#pragma warning disable CS0612 // Type or member is obsolete serviceCollection.AddSingleton(new TestStartupServicesFilter(1, overrideAfterService: false)); serviceCollection.AddSingleton(new TestStartupServicesFilter(2, overrideAfterService: true)); +#pragma warning restore CS0612 // Type or member is obsolete var services = serviceCollection.BuildServiceProvider(); var type = typeof(VoidReturningStartupServicesFiltersStartup); @@ -63,15 +65,19 @@ public void ConventionalStartupClass_StartupServicesFilters_ThrowsIfStartupBuild { var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton, DefaultServiceProviderFactory>(); +#pragma warning disable CS0612 // Type or member is obsolete serviceCollection.AddSingleton(new TestStartupServicesFilter(1, overrideAfterService: false)); +#pragma warning restore CS0612 // Type or member is obsolete var services = serviceCollection.BuildServiceProvider(); var type = typeof(IServiceProviderReturningStartupServicesFiltersStartup); var startup = StartupLoader.LoadMethods(services, type, ""); +#pragma warning disable CS0612 // Type or member is obsolete var expectedMessage = $"A ConfigureServices method that returns an {nameof(IServiceProvider)} is " + $"not compatible with the use of one or more {nameof(IStartupConfigureServicesFilter)}. " + $"Use a void returning ConfigureServices method instead or a ConfigureContainer method."; +#pragma warning restore CS0612 // Type or member is obsolete var exception = Assert.Throws(() => startup.ConfigureServicesDelegate(serviceCollection)); @@ -83,8 +89,10 @@ public void ConventionalStartupClass_ConfigureContainerFilters_WrapInRegistratio { var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton, MyContainerFactory>(); +#pragma warning disable CS0612 // Type or member is obsolete serviceCollection.AddSingleton>(new TestConfigureContainerFilter(1, overrideAfterService: true)); serviceCollection.AddSingleton>(new TestConfigureContainerFilter(2, overrideAfterService: true)); +#pragma warning restore CS0612 // Type or member is obsolete var services = serviceCollection.BuildServiceProvider(); var type = typeof(ConfigureContainerStartupServicesFiltersStartup); @@ -103,8 +111,10 @@ public void ConventionalStartupClass_ConfigureContainerFilters_RunsAllFilters() { var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton, MyContainerFactory>(); +#pragma warning disable CS0612 // Type or member is obsolete serviceCollection.AddSingleton>(new TestConfigureContainerFilter(1, overrideAfterService: false)); serviceCollection.AddSingleton>(new TestConfigureContainerFilter(2, overrideAfterService: true)); +#pragma warning restore CS0612 // Type or member is obsolete var services = serviceCollection.BuildServiceProvider(); var type = typeof(ConfigureContainerStartupServicesFiltersStartup); @@ -123,8 +133,10 @@ public void ConventionalStartupClass_ConfigureContainerFilters_RunAfterConfigure { var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton, MyContainerFactory>(); +#pragma warning disable CS0612 // Type or member is obsolete serviceCollection.AddSingleton(new TestStartupServicesFilter(1, overrideAfterService: false)); serviceCollection.AddSingleton>(new TestConfigureContainerFilter(2, overrideAfterService: true)); +#pragma warning restore CS0612 // Type or member is obsolete var services = serviceCollection.BuildServiceProvider(); var type = typeof(ConfigureServicesAndConfigureContainerStartup); @@ -170,7 +182,9 @@ public void Configure(IApplicationBuilder builder) } } +#pragma warning disable CS0612 // Type or member is obsolete public class TestConfigureContainerFilter : IStartupConfigureContainerFilter +#pragma warning restore CS0612 // Type or member is obsolete { public TestConfigureContainerFilter(object additionalData, bool overrideAfterService) { @@ -217,7 +231,9 @@ public void Configure(IApplicationBuilder builder) } } +#pragma warning disable CS0612 // Type or member is obsolete public class TestStartupServicesFilter : IStartupConfigureServicesFilter +#pragma warning restore CS0612 // Type or member is obsolete { public TestStartupServicesFilter(object additionalData, bool overrideAfterService) { diff --git a/src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsLoaderTests.cs b/src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsLoaderTests.cs index 989ea4300eb1..62f9adaae63e 100644 --- a/src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsLoaderTests.cs +++ b/src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsLoaderTests.cs @@ -5,7 +5,6 @@ using System.IO; using System.Linq; using System.Text; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.FileProviders; using Xunit; diff --git a/src/Hosting/Hosting/test/WebHostBuilderTests.cs b/src/Hosting/Hosting/test/WebHostBuilderTests.cs index 55e0de8238fd..ae7e111b2d5c 100644 --- a/src/Hosting/Hosting/test/WebHostBuilderTests.cs +++ b/src/Hosting/Hosting/test/WebHostBuilderTests.cs @@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Fakes; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Tests.Fakes; using Microsoft.AspNetCore.Http; diff --git a/src/Hosting/Hosting/test/WebHostConfigurationsTests.cs b/src/Hosting/Hosting/test/WebHostConfigurationsTests.cs index 35ac6f8b4c78..f21947c7299a 100644 --- a/src/Hosting/Hosting/test/WebHostConfigurationsTests.cs +++ b/src/Hosting/Hosting/test/WebHostConfigurationsTests.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Xunit; diff --git a/src/Hosting/TestHost/src/ApplicationWrapper.cs b/src/Hosting/TestHost/src/ApplicationWrapper.cs new file mode 100644 index 000000000000..0184053889ef --- /dev/null +++ b/src/Hosting/TestHost/src/ApplicationWrapper.cs @@ -0,0 +1,62 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting.Server; +using Microsoft.AspNetCore.Http.Features; + +namespace Microsoft.AspNetCore.TestHost +{ + internal abstract class ApplicationWrapper + { + internal abstract object CreateContext(IFeatureCollection features); + + internal abstract Task ProcessRequestAsync(object context); + + internal abstract void DisposeContext(object context, Exception exception); + } + + internal class ApplicationWrapper : ApplicationWrapper, IHttpApplication + { + private readonly IHttpApplication _application; + private readonly Action _preProcessRequestAsync; + + public ApplicationWrapper(IHttpApplication application, Action preProcessRequestAsync) + { + _application = application; + _preProcessRequestAsync = preProcessRequestAsync; + } + + internal override object CreateContext(IFeatureCollection features) + { + return ((IHttpApplication)this).CreateContext(features); + } + + TContext IHttpApplication.CreateContext(IFeatureCollection features) + { + return _application.CreateContext(features); + } + + internal override void DisposeContext(object context, Exception exception) + { + ((IHttpApplication)this).DisposeContext((TContext)context, exception); + } + + void IHttpApplication.DisposeContext(TContext context, Exception exception) + { + _application.DisposeContext(context, exception); + } + + internal override Task ProcessRequestAsync(object context) + { + return ((IHttpApplication)this).ProcessRequestAsync((TContext)context); + } + + Task IHttpApplication.ProcessRequestAsync(TContext context) + { + _preProcessRequestAsync(); + return _application.ProcessRequestAsync(context); + } + } +} diff --git a/src/Hosting/TestHost/src/ClientHandler.cs b/src/Hosting/TestHost/src/ClientHandler.cs index f9e8547af2e2..cdfd7a0b07a7 100644 --- a/src/Hosting/TestHost/src/ClientHandler.cs +++ b/src/Hosting/TestHost/src/ClientHandler.cs @@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Context = Microsoft.AspNetCore.Hosting.Internal.HostingApplication.Context; namespace Microsoft.AspNetCore.TestHost { @@ -23,7 +22,7 @@ namespace Microsoft.AspNetCore.TestHost /// public class ClientHandler : HttpMessageHandler { - private readonly IHttpApplication _application; + private readonly ApplicationWrapper _application; private readonly PathString _pathBase; /// @@ -31,7 +30,7 @@ public class ClientHandler : HttpMessageHandler /// /// The base path. /// The . - internal ClientHandler(PathString pathBase, IHttpApplication application) + internal ClientHandler(PathString pathBase, ApplicationWrapper application) { _application = application ?? throw new ArgumentNullException(nameof(application)); diff --git a/src/Hosting/TestHost/src/HttpContextBuilder.cs b/src/Hosting/TestHost/src/HttpContextBuilder.cs index 287e4aacf7b2..b03137f1407d 100644 --- a/src/Hosting/TestHost/src/HttpContextBuilder.cs +++ b/src/Hosting/TestHost/src/HttpContextBuilder.cs @@ -2,19 +2,16 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Globalization; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication; namespace Microsoft.AspNetCore.TestHost { internal class HttpContextBuilder : IHttpBodyControlFeature { - private readonly IHttpApplication _application; + private readonly ApplicationWrapper _application; private readonly bool _preserveExecutionContext; private readonly HttpContext _httpContext; @@ -25,10 +22,10 @@ internal class HttpContextBuilder : IHttpBodyControlFeature private readonly ResponseTrailersFeature _responseTrailersFeature = new ResponseTrailersFeature(); private bool _pipelineFinished; private bool _returningResponse; - private Context _testContext; + private object _testContext; private Action _responseReadCompleteCallback; - internal HttpContextBuilder(IHttpApplication application, bool allowSynchronousIO, bool preserveExecutionContext) + internal HttpContextBuilder(ApplicationWrapper application, bool allowSynchronousIO, bool preserveExecutionContext) { _application = application ?? throw new ArgumentNullException(nameof(application)); AllowSynchronousIO = allowSynchronousIO; diff --git a/src/Hosting/TestHost/src/TestServer.cs b/src/Hosting/TestHost/src/TestServer.cs index 07932f74576f..872335f4649e 100644 --- a/src/Hosting/TestHost/src/TestServer.cs +++ b/src/Hosting/TestHost/src/TestServer.cs @@ -6,11 +6,9 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Context = Microsoft.AspNetCore.Hosting.Internal.HostingApplication.Context; namespace Microsoft.AspNetCore.TestHost { @@ -18,7 +16,7 @@ public class TestServer : IServer { private IWebHost _hostInstance; private bool _disposed = false; - private IHttpApplication _application; + private ApplicationWrapper _application; /// /// For use with IHostBuilder or IWebHostBuilder. @@ -87,7 +85,7 @@ public IWebHost Host /// public bool PreserveExecutionContext { get; set; } - private IHttpApplication Application + private ApplicationWrapper Application { get => _application ?? throw new InvalidOperationException("The server has not been started or no web application was configured."); } @@ -163,7 +161,7 @@ public void Dispose() Task IServer.StartAsync(IHttpApplication application, CancellationToken cancellationToken) { - _application = new ApplicationWrapper((IHttpApplication)application, () => + _application = new ApplicationWrapper(application, () => { if (_disposed) { @@ -178,33 +176,5 @@ Task IServer.StopAsync(CancellationToken cancellationToken) { return Task.CompletedTask; } - - private class ApplicationWrapper : IHttpApplication - { - private readonly IHttpApplication _application; - private readonly Action _preProcessRequestAsync; - - public ApplicationWrapper(IHttpApplication application, Action preProcessRequestAsync) - { - _application = application; - _preProcessRequestAsync = preProcessRequestAsync; - } - - public TContext CreateContext(IFeatureCollection contextFeatures) - { - return _application.CreateContext(contextFeatures); - } - - public void DisposeContext(TContext context, Exception exception) - { - _application.DisposeContext(context, exception); - } - - public Task ProcessRequestAsync(TContext context) - { - _preProcessRequestAsync(); - return _application.ProcessRequestAsync(context); - } - } } } diff --git a/src/Hosting/TestHost/src/WebHostBuilderExtensions.cs b/src/Hosting/TestHost/src/WebHostBuilderExtensions.cs index 7e7ba6780912..c2051497cd46 100644 --- a/src/Hosting/TestHost/src/WebHostBuilderExtensions.cs +++ b/src/Hosting/TestHost/src/WebHostBuilderExtensions.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Net.Http; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.Extensions.DependencyInjection; @@ -61,9 +60,11 @@ public static IWebHostBuilder ConfigureTestServices(this IWebHostBuilder webHost } else { +#pragma warning disable CS0612 // Type or member is obsolete webHostBuilder.ConfigureServices( s => s.AddSingleton( new ConfigureTestServicesStartupConfigureServicesFilter(servicesConfiguration))); +#pragma warning restore CS0612 // Type or member is obsolete } return webHostBuilder; @@ -81,9 +82,11 @@ public static IWebHostBuilder ConfigureTestContainer(this IWebHostBu throw new ArgumentNullException(nameof(servicesConfiguration)); } +#pragma warning disable CS0612 // Type or member is obsolete webHostBuilder.ConfigureServices( s => s.AddSingleton>( new ConfigureTestServicesStartupConfigureContainerFilter(servicesConfiguration))); +#pragma warning restore CS0612 // Type or member is obsolete return webHostBuilder; } @@ -129,7 +132,9 @@ public static IWebHostBuilder UseSolutionRelativeContentRoot( throw new InvalidOperationException($"Solution root could not be located using application root {applicationBasePath}."); } +#pragma warning disable CS0612 // Type or member is obsolete private class ConfigureTestServicesStartupConfigureServicesFilter : IStartupConfigureServicesFilter +#pragma warning restore CS0612 // Type or member is obsolete { private readonly Action _servicesConfiguration; @@ -151,7 +156,9 @@ public Action ConfigureServices(Action n }; } +#pragma warning disable CS0612 // Type or member is obsolete private class ConfigureTestServicesStartupConfigureContainerFilter : IStartupConfigureContainerFilter +#pragma warning restore CS0612 // Type or member is obsolete { private readonly Action _servicesConfiguration; diff --git a/src/Hosting/TestHost/src/WebSocketClient.cs b/src/Hosting/TestHost/src/WebSocketClient.cs index 4d1a6740d39e..d312c0ebbd6e 100644 --- a/src/Hosting/TestHost/src/WebSocketClient.cs +++ b/src/Hosting/TestHost/src/WebSocketClient.cs @@ -8,19 +8,17 @@ using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Context = Microsoft.AspNetCore.Hosting.Internal.HostingApplication.Context; namespace Microsoft.AspNetCore.TestHost { public class WebSocketClient { - private readonly IHttpApplication _application; + private readonly ApplicationWrapper _application; private readonly PathString _pathBase; - internal WebSocketClient(PathString pathBase, IHttpApplication application) + internal WebSocketClient(PathString pathBase, ApplicationWrapper application) { _application = application ?? throw new ArgumentNullException(nameof(application)); diff --git a/src/Hosting/TestHost/test/ClientHandlerTests.cs b/src/Hosting/TestHost/test/ClientHandlerTests.cs index ad0fa61c7038..27ae5b6f4ef9 100644 --- a/src/Hosting/TestHost/test/ClientHandlerTests.cs +++ b/src/Hosting/TestHost/test/ClientHandlerTests.cs @@ -17,7 +17,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Xunit; -using Context = Microsoft.AspNetCore.Hosting.Internal.HostingApplication.Context; namespace Microsoft.AspNetCore.TestHost { @@ -421,7 +420,7 @@ public Task ExceptionFromOnStartingWithErrorHandlerIsReported() HttpCompletionOption.ResponseHeadersRead)); } - private class DummyApplication : IHttpApplication + private class DummyApplication : ApplicationWrapper, IHttpApplication { RequestDelegate _application; @@ -430,26 +429,41 @@ public DummyApplication(RequestDelegate application) _application = application; } - public Context CreateContext(IFeatureCollection contextFeatures) + internal override object CreateContext(IFeatureCollection features) { - return new Context() + return ((IHttpApplication)this).CreateContext(features); + } + + HostingApplication.Context IHttpApplication.CreateContext(IFeatureCollection contextFeatures) + { + return new HostingApplication.Context() { HttpContext = new DefaultHttpContext(contextFeatures) }; } - public void DisposeContext(Context context, Exception exception) + internal override void DisposeContext(object context, Exception exception) { + ((IHttpApplication)this).DisposeContext((HostingApplication.Context)context, exception); + } + void IHttpApplication.DisposeContext(HostingApplication.Context context, Exception exception) + { + + } + + internal override Task ProcessRequestAsync(object context) + { + return ((IHttpApplication)this).ProcessRequestAsync((HostingApplication.Context)context); } - public Task ProcessRequestAsync(Context context) + Task IHttpApplication.ProcessRequestAsync(HostingApplication.Context context) { return _application(context.HttpContext); } } - private class InspectingApplication : IHttpApplication + private class InspectingApplication : ApplicationWrapper, IHttpApplication { Action _inspector; @@ -458,21 +472,36 @@ public InspectingApplication(Action inspector) _inspector = inspector; } - public Context CreateContext(IFeatureCollection contextFeatures) + internal override object CreateContext(IFeatureCollection features) + { + return ((IHttpApplication)this).CreateContext(features); + } + + HostingApplication.Context IHttpApplication.CreateContext(IFeatureCollection contextFeatures) { _inspector(contextFeatures); - return new Context() + return new HostingApplication.Context() { HttpContext = new DefaultHttpContext(contextFeatures) }; } - public void DisposeContext(Context context, Exception exception) + internal override void DisposeContext(object context, Exception exception) { + ((IHttpApplication)this).DisposeContext((HostingApplication.Context)context, exception); + } + void IHttpApplication.DisposeContext(HostingApplication.Context context, Exception exception) + { + + } + + internal override Task ProcessRequestAsync(object context) + { + return ((IHttpApplication)this).ProcessRequestAsync((HostingApplication.Context)context); } - public Task ProcessRequestAsync(Context context) + Task IHttpApplication.ProcessRequestAsync(HostingApplication.Context context) { return Task.FromResult(0); } diff --git a/src/Servers/Kestrel/Kestrel/test/KestrelConfigurationBuilderTests.cs b/src/Servers/Kestrel/Kestrel/test/KestrelConfigurationBuilderTests.cs index fbcf3b568ea6..c1b125112301 100644 --- a/src/Servers/Kestrel/Kestrel/test/KestrelConfigurationBuilderTests.cs +++ b/src/Servers/Kestrel/Kestrel/test/KestrelConfigurationBuilderTests.cs @@ -7,13 +7,13 @@ using System.Linq; using System.Security.Cryptography.X509Certificates; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Hosting.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.AspNetCore.Testing; using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using Xunit; @@ -24,10 +24,9 @@ public class KestrelConfigurationBuilderTests private KestrelServerOptions CreateServerOptions() { var serverOptions = new KestrelServerOptions(); - var env = new HostingEnvironment { ApplicationName = "TestApplication" }; + var env = new MockHostingEnvironment { ApplicationName = "TestApplication" }; serverOptions.ApplicationServices = new ServiceCollection() .AddLogging() - .AddSingleton(env) .AddSingleton(env) .BuildServiceProvider(); return serverOptions; @@ -462,5 +461,13 @@ private static string GetCertificatePath() basePath = basePath ?? (home != null ? Path.Combine(home, ".aspnet", "https") : null); return Path.Combine(basePath, $"TestApplication.pfx"); } + + private class MockHostingEnvironment : IHostEnvironment + { + public string ApplicationName { get; set; } + public string EnvironmentName { get; set; } + public string ContentRootPath { get; set; } + public IFileProvider ContentRootFileProvider { get; set; } + } } } From a1ff5c6260e31897e78937e438a6c29c7be84a58 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 24 Jun 2019 15:12:06 -0700 Subject: [PATCH 2/2] Wart removal --- .../src/Microsoft.AspNetCore.Hosting.csproj | 6 +-- .../TestHost/test/ClientHandlerTests.cs | 39 ++++++++++--------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj b/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj index 3f4399d24ec6..dfc668f4a2d4 100644 --- a/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj +++ b/src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj @@ -1,4 +1,4 @@ - + ASP.NET Core hosting infrastructure and startup logic for web applications. @@ -31,8 +31,4 @@ - - - - diff --git a/src/Hosting/TestHost/test/ClientHandlerTests.cs b/src/Hosting/TestHost/test/ClientHandlerTests.cs index 27ae5b6f4ef9..01408813f3ea 100644 --- a/src/Hosting/TestHost/test/ClientHandlerTests.cs +++ b/src/Hosting/TestHost/test/ClientHandlerTests.cs @@ -12,8 +12,6 @@ using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Testing; -using Microsoft.AspNetCore.Testing.xunit; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Xunit; @@ -420,7 +418,7 @@ public Task ExceptionFromOnStartingWithErrorHandlerIsReported() HttpCompletionOption.ResponseHeadersRead)); } - private class DummyApplication : ApplicationWrapper, IHttpApplication + private class DummyApplication : ApplicationWrapper, IHttpApplication { RequestDelegate _application; @@ -431,12 +429,12 @@ public DummyApplication(RequestDelegate application) internal override object CreateContext(IFeatureCollection features) { - return ((IHttpApplication)this).CreateContext(features); + return ((IHttpApplication)this).CreateContext(features); } - HostingApplication.Context IHttpApplication.CreateContext(IFeatureCollection contextFeatures) + TestHostingContext IHttpApplication.CreateContext(IFeatureCollection contextFeatures) { - return new HostingApplication.Context() + return new TestHostingContext() { HttpContext = new DefaultHttpContext(contextFeatures) }; @@ -444,26 +442,26 @@ internal override object CreateContext(IFeatureCollection features) internal override void DisposeContext(object context, Exception exception) { - ((IHttpApplication)this).DisposeContext((HostingApplication.Context)context, exception); + ((IHttpApplication)this).DisposeContext((TestHostingContext)context, exception); } - void IHttpApplication.DisposeContext(HostingApplication.Context context, Exception exception) + void IHttpApplication.DisposeContext(TestHostingContext context, Exception exception) { } internal override Task ProcessRequestAsync(object context) { - return ((IHttpApplication)this).ProcessRequestAsync((HostingApplication.Context)context); + return ((IHttpApplication)this).ProcessRequestAsync((TestHostingContext)context); } - Task IHttpApplication.ProcessRequestAsync(HostingApplication.Context context) + Task IHttpApplication.ProcessRequestAsync(TestHostingContext context) { return _application(context.HttpContext); } } - private class InspectingApplication : ApplicationWrapper, IHttpApplication + private class InspectingApplication : ApplicationWrapper, IHttpApplication { Action _inspector; @@ -474,13 +472,13 @@ public InspectingApplication(Action inspector) internal override object CreateContext(IFeatureCollection features) { - return ((IHttpApplication)this).CreateContext(features); + return ((IHttpApplication)this).CreateContext(features); } - HostingApplication.Context IHttpApplication.CreateContext(IFeatureCollection contextFeatures) + TestHostingContext IHttpApplication.CreateContext(IFeatureCollection contextFeatures) { _inspector(contextFeatures); - return new HostingApplication.Context() + return new TestHostingContext() { HttpContext = new DefaultHttpContext(contextFeatures) }; @@ -488,25 +486,30 @@ internal override object CreateContext(IFeatureCollection features) internal override void DisposeContext(object context, Exception exception) { - ((IHttpApplication)this).DisposeContext((HostingApplication.Context)context, exception); + ((IHttpApplication)this).DisposeContext((TestHostingContext)context, exception); } - void IHttpApplication.DisposeContext(HostingApplication.Context context, Exception exception) + void IHttpApplication.DisposeContext(TestHostingContext context, Exception exception) { } internal override Task ProcessRequestAsync(object context) { - return ((IHttpApplication)this).ProcessRequestAsync((HostingApplication.Context)context); + return ((IHttpApplication)this).ProcessRequestAsync((TestHostingContext)context); } - Task IHttpApplication.ProcessRequestAsync(HostingApplication.Context context) + Task IHttpApplication.ProcessRequestAsync(TestHostingContext context) { return Task.FromResult(0); } } + private class TestHostingContext + { + public HttpContext HttpContext { get; set; } + } + [Fact] public async Task ClientHandlerCreateContextWithDefaultRequestParameters() {