Remove Hosting.Internal APIs (#11505)

* Remove Hosting.Internal APIs #11312
This commit is contained in:
Chris Ross 2019-06-24 21:55:09 -07:00 committed by David Fowler
parent 5ace0efa49
commit f3f9a1cdbc
58 changed files with 245 additions and 294 deletions

View File

@ -65,6 +65,16 @@ namespace Microsoft.AspNetCore.Hosting
void Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app);
System.IServiceProvider ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services);
}
[System.ObsoleteAttribute]
public partial interface IStartupConfigureContainerFilter<TContainerBuilder>
{
System.Action<TContainerBuilder> ConfigureContainer(System.Action<TContainerBuilder> container);
}
[System.ObsoleteAttribute]
public partial interface IStartupConfigureServicesFilter
{
System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> ConfigureServices(System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> next);
}
public partial interface IStartupFilter
{
System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> Configure(System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> next);
@ -115,14 +125,3 @@ namespace Microsoft.AspNetCore.Hosting
public static readonly string WebRootKey;
}
}
namespace Microsoft.AspNetCore.Hosting.Internal
{
public partial interface IStartupConfigureContainerFilter<TContainerBuilder>
{
System.Action<TContainerBuilder> ConfigureContainer(System.Action<TContainerBuilder> container);
}
public partial interface IStartupConfigureServicesFilter
{
System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> ConfigureServices(System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> next);
}
}

View File

@ -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
{
/// <summary>
/// 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.
/// </summary>
[Obsolete]
public interface IStartupConfigureContainerFilter<TContainerBuilder>
{
Action<TContainerBuilder> ConfigureContainer(Action<TContainerBuilder> container);

View File

@ -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
{
/// <summary>
/// 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.
/// </summary>
[Obsolete]
public interface IStartupConfigureServicesFilter
{
Action<IServiceCollection> ConfigureServices(Action<IServiceCollection> next);

View File

@ -71,138 +71,6 @@ namespace Microsoft.AspNetCore.Hosting.Builder
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<Microsoft.AspNetCore.Hosting.Internal.ApplicationLifetime> 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<Microsoft.AspNetCore.Builder.IApplicationBuilder> Build(object instance) { throw null; }
}
public partial class ConfigureContainerBuilder
{
public ConfigureContainerBuilder(System.Reflection.MethodInfo configureContainerMethod) { }
public System.Func<System.Action<object>, System.Action<object>> 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<object> 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<Microsoft.Extensions.DependencyInjection.IServiceCollection, System.IServiceProvider>, System.Func<Microsoft.Extensions.DependencyInjection.IServiceCollection, System.IServiceProvider>> StartupServiceFilters { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
public System.Func<Microsoft.Extensions.DependencyInjection.IServiceCollection, System.IServiceProvider> 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<Microsoft.AspNetCore.Hosting.Internal.HostedServiceExecutor> logger, System.Collections.Generic.IEnumerable<Microsoft.Extensions.Hosting.IHostedService> 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<Microsoft.AspNetCore.Hosting.Internal.HostingApplication.Context>
{
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<Microsoft.AspNetCore.Builder.IApplicationBuilder> configure, System.Func<Microsoft.Extensions.DependencyInjection.IServiceCollection, System.IServiceProvider> configureServices) { }
public System.Action<Microsoft.AspNetCore.Builder.IApplicationBuilder> ConfigureDelegate { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public System.Func<Microsoft.Extensions.DependencyInjection.IServiceCollection, System.IServiceProvider> 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<string> HostingStartupAssemblies { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
public System.Collections.Generic.IReadOnlyList<string> 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<string> 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

View File

@ -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

View File

@ -16,7 +16,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.ObjectPool;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
internal class GenericWebHostBuilder : IWebHostBuilder, ISupportsStartup, ISupportsUseDefaultServiceProvider
{

View File

@ -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
{

View File

@ -22,7 +22,7 @@ using Microsoft.Extensions.Options;
using Microsoft.Extensions.StackTrace.Sources;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
internal class GenericWebHostService : IHostedService
{

View File

@ -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.AspNetCore.Builder;
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.

View File

@ -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
{

View File

@ -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
{

View File

@ -1,6 +1,5 @@
using System;
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Internal;
namespace Microsoft.Extensions.Hosting
{

View File

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
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.
namespace Microsoft.AspNetCore.Hosting.Internal
using System.Diagnostics;
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Helpers for getting the right values from Activity no matter the format (w3c or hierarchical)

View File

@ -6,13 +6,13 @@ using System.Threading;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Allows consumers to perform cleanup during a graceful shutdown.
/// </summary>
#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();

View File

@ -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)
{

View File

@ -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)
{

View File

@ -6,9 +6,9 @@ using System.Linq;
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)
{

View File

@ -8,9 +8,9 @@ using System.Threading.Tasks;
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<IHostedService> _services;
private readonly ILogger<HostedServiceExecutor> _logger;

View File

@ -9,9 +9,9 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
public class HostingApplication : IHttpApplication<HostingApplication.Context>
internal class HostingApplication : IHttpApplication<HostingApplication.Context>
{
private readonly RequestDelegate _application;
private readonly IHttpContextFactory _httpContextFactory;
@ -55,7 +55,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
_diagnostics.ContextDisposed(context);
}
public struct Context
internal struct Context
{
public HttpContext HttpContext { get; set; }
public IDisposable Scope { get; set; }

View File

@ -9,7 +9,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
internal class HostingApplicationDiagnostics
{

View File

@ -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;

View File

@ -5,12 +5,12 @@ using System;
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 @@ namespace Microsoft.AspNetCore.Hosting.Internal
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)
{

View File

@ -6,9 +6,9 @@ using System.Diagnostics.Tracing;
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();

View File

@ -10,7 +10,7 @@ using System.Reflection;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
internal static class HostingLoggerExtensions
{

View File

@ -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.Collections.Generic;
using System.Globalization;
using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
internal class HostingRequestFinishedLog : IReadOnlyList<KeyValuePair<string, object>>
{

View File

@ -7,7 +7,7 @@ using System.Collections.Generic;
using System.Globalization;
using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
internal class HostingRequestStartingLog : IReadOnlyList<KeyValuePair<string, object>>
{

View File

@ -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
{

View File

@ -3,7 +3,7 @@
using System.Reflection;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
internal static class MethodInfoExtensions
{

View File

@ -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
{

View File

@ -8,9 +8,9 @@ using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
public class StartupLoader
internal class StartupLoader
{
// Creates an <see cref="StartupMethods"/> instance with the actions to run for configuring the application services and the
// request pipeline of the application.
@ -157,7 +157,9 @@ namespace Microsoft.AspNetCore.Hosting.Internal
IServiceProvider RunPipeline(IServiceCollection services)
{
#pragma warning disable CS0612 // Type or member is obsolete
var filters = HostingServiceProvider.GetRequiredService<IEnumerable<IStartupConfigureServicesFilter>>().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 @@ namespace Microsoft.AspNetCore.Hosting.Internal
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 @@ namespace Microsoft.AspNetCore.Hosting.Internal
void RunPipeline(TContainerBuilder containerBuilder)
{
var filters = HostingServiceProvider
#pragma warning disable CS0612 // Type or member is obsolete
.GetRequiredService<IEnumerable<IStartupConfigureContainerFilter<TContainerBuilder>>>()
#pragma warning restore CS0612 // Type or member is obsolete
.Reverse()
.ToArray();

View File

@ -6,9 +6,9 @@ using System.Diagnostics;
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<IApplicationBuilder> configure, Func<IServiceCollection, IServiceProvider> configureServices)
{
@ -25,4 +25,4 @@ namespace Microsoft.AspNetCore.Hosting.Internal
public Action<IApplicationBuilder> ConfigureDelegate { get; }
}
}
}

View File

@ -25,7 +25,7 @@ using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.StackTrace.Sources;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
internal class WebHost : IWebHost, IAsyncDisposable
{

View File

@ -4,7 +4,7 @@
using System;
using System.Threading;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
internal class WebHostLifetime : IDisposable
{

View File

@ -7,9 +7,9 @@ using System.Globalization;
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 @@ namespace Microsoft.AspNetCore.Hosting.Internal
return list;
}
}
}
}

View File

@ -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)
{

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>ASP.NET Core hosting infrastructure and startup logic for web applications.</Description>

View File

@ -7,9 +7,9 @@ using System.Runtime.ExceptionServices;
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;

View File

@ -9,7 +9,6 @@ using System.Linq;
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;

View File

@ -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;

View File

@ -6,7 +6,6 @@ using System.Threading;
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

View File

@ -4,7 +4,6 @@
using System;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting.Internal;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

View File

@ -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;

View File

@ -7,7 +7,6 @@ using System.Diagnostics;
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;

View File

@ -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;

View File

@ -13,7 +13,7 @@ using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Testing.xunit;
using Xunit;
namespace Microsoft.AspNetCore.Hosting.Internal
namespace Microsoft.AspNetCore.Hosting
{
public class HostingEventSourceTests
{

View File

@ -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
{

View File

@ -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 @@ namespace Microsoft.AspNetCore.Hosting.Tests
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<IServiceProviderFactory<IServiceCollection>, DefaultServiceProviderFactory>();
#pragma warning disable CS0612 // Type or member is obsolete
serviceCollection.AddSingleton<IStartupConfigureServicesFilter>(new TestStartupServicesFilter(1, overrideAfterService: true));
serviceCollection.AddSingleton<IStartupConfigureServicesFilter>(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 @@ namespace Microsoft.AspNetCore.Hosting.Tests
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<IServiceProviderFactory<IServiceCollection>, DefaultServiceProviderFactory>();
#pragma warning disable CS0612 // Type or member is obsolete
serviceCollection.AddSingleton<IStartupConfigureServicesFilter>(new TestStartupServicesFilter(1, overrideAfterService: false));
serviceCollection.AddSingleton<IStartupConfigureServicesFilter>(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 @@ namespace Microsoft.AspNetCore.Hosting.Tests
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<IServiceProviderFactory<IServiceCollection>, DefaultServiceProviderFactory>();
#pragma warning disable CS0612 // Type or member is obsolete
serviceCollection.AddSingleton<IStartupConfigureServicesFilter>(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<InvalidOperationException>(() => startup.ConfigureServicesDelegate(serviceCollection));
@ -83,8 +89,10 @@ namespace Microsoft.AspNetCore.Hosting.Tests
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<IServiceProviderFactory<MyContainer>, MyContainerFactory>();
#pragma warning disable CS0612 // Type or member is obsolete
serviceCollection.AddSingleton<IStartupConfigureContainerFilter<MyContainer>>(new TestConfigureContainerFilter(1, overrideAfterService: true));
serviceCollection.AddSingleton<IStartupConfigureContainerFilter<MyContainer>>(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 @@ namespace Microsoft.AspNetCore.Hosting.Tests
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<IServiceProviderFactory<MyContainer>, MyContainerFactory>();
#pragma warning disable CS0612 // Type or member is obsolete
serviceCollection.AddSingleton<IStartupConfigureContainerFilter<MyContainer>>(new TestConfigureContainerFilter(1, overrideAfterService: false));
serviceCollection.AddSingleton<IStartupConfigureContainerFilter<MyContainer>>(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 @@ namespace Microsoft.AspNetCore.Hosting.Tests
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<IServiceProviderFactory<MyContainer>, MyContainerFactory>();
#pragma warning disable CS0612 // Type or member is obsolete
serviceCollection.AddSingleton<IStartupConfigureServicesFilter>(new TestStartupServicesFilter(1, overrideAfterService: false));
serviceCollection.AddSingleton<IStartupConfigureContainerFilter<MyContainer>>(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 @@ namespace Microsoft.AspNetCore.Hosting.Tests
}
}
#pragma warning disable CS0612 // Type or member is obsolete
public class TestConfigureContainerFilter : IStartupConfigureContainerFilter<MyContainer>
#pragma warning restore CS0612 // Type or member is obsolete
{
public TestConfigureContainerFilter(object additionalData, bool overrideAfterService)
{
@ -217,7 +231,9 @@ namespace Microsoft.AspNetCore.Hosting.Tests
}
}
#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)
{

View File

@ -5,7 +5,6 @@ using System;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Hosting.Internal;
using Microsoft.Extensions.FileProviders;
using Xunit;

View File

@ -11,7 +11,6 @@ using System.Threading.Tasks;
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;

View File

@ -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;

View File

@ -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<TContext> : ApplicationWrapper, IHttpApplication<TContext>
{
private readonly IHttpApplication<TContext> _application;
private readonly Action _preProcessRequestAsync;
public ApplicationWrapper(IHttpApplication<TContext> application, Action preProcessRequestAsync)
{
_application = application;
_preProcessRequestAsync = preProcessRequestAsync;
}
internal override object CreateContext(IFeatureCollection features)
{
return ((IHttpApplication<TContext>)this).CreateContext(features);
}
TContext IHttpApplication<TContext>.CreateContext(IFeatureCollection features)
{
return _application.CreateContext(features);
}
internal override void DisposeContext(object context, Exception exception)
{
((IHttpApplication<TContext>)this).DisposeContext((TContext)context, exception);
}
void IHttpApplication<TContext>.DisposeContext(TContext context, Exception exception)
{
_application.DisposeContext(context, exception);
}
internal override Task ProcessRequestAsync(object context)
{
return ((IHttpApplication<TContext>)this).ProcessRequestAsync((TContext)context);
}
Task IHttpApplication<TContext>.ProcessRequestAsync(TContext context)
{
_preProcessRequestAsync();
return _application.ProcessRequestAsync(context);
}
}
}

View File

@ -13,7 +13,6 @@ 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
{
@ -23,7 +22,7 @@ namespace Microsoft.AspNetCore.TestHost
/// </summary>
public class ClientHandler : HttpMessageHandler
{
private readonly IHttpApplication<Context> _application;
private readonly ApplicationWrapper _application;
private readonly PathString _pathBase;
/// <summary>
@ -31,7 +30,7 @@ namespace Microsoft.AspNetCore.TestHost
/// </summary>
/// <param name="pathBase">The base path.</param>
/// <param name="application">The <see cref="IHttpApplication{TContext}"/>.</param>
internal ClientHandler(PathString pathBase, IHttpApplication<Context> application)
internal ClientHandler(PathString pathBase, ApplicationWrapper application)
{
_application = application ?? throw new ArgumentNullException(nameof(application));

View File

@ -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<Context> _application;
private readonly ApplicationWrapper _application;
private readonly bool _preserveExecutionContext;
private readonly HttpContext _httpContext;
@ -25,10 +22,10 @@ namespace Microsoft.AspNetCore.TestHost
private readonly ResponseTrailersFeature _responseTrailersFeature = new ResponseTrailersFeature();
private bool _pipelineFinished;
private bool _returningResponse;
private Context _testContext;
private object _testContext;
private Action<HttpContext> _responseReadCompleteCallback;
internal HttpContextBuilder(IHttpApplication<Context> application, bool allowSynchronousIO, bool preserveExecutionContext)
internal HttpContextBuilder(ApplicationWrapper application, bool allowSynchronousIO, bool preserveExecutionContext)
{
_application = application ?? throw new ArgumentNullException(nameof(application));
AllowSynchronousIO = allowSynchronousIO;

View File

@ -6,11 +6,9 @@ using System.Net.Http;
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 @@ namespace Microsoft.AspNetCore.TestHost
{
private IWebHost _hostInstance;
private bool _disposed = false;
private IHttpApplication<Context> _application;
private ApplicationWrapper _application;
/// <summary>
/// For use with IHostBuilder or IWebHostBuilder.
@ -87,7 +85,7 @@ namespace Microsoft.AspNetCore.TestHost
/// </summary>
public bool PreserveExecutionContext { get; set; }
private IHttpApplication<Context> 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 @@ namespace Microsoft.AspNetCore.TestHost
Task IServer.StartAsync<TContext>(IHttpApplication<TContext> application, CancellationToken cancellationToken)
{
_application = new ApplicationWrapper<Context>((IHttpApplication<Context>)application, () =>
_application = new ApplicationWrapper<TContext>(application, () =>
{
if (_disposed)
{
@ -178,33 +176,5 @@ namespace Microsoft.AspNetCore.TestHost
{
return Task.CompletedTask;
}
private class ApplicationWrapper<TContext> : IHttpApplication<TContext>
{
private readonly IHttpApplication<TContext> _application;
private readonly Action _preProcessRequestAsync;
public ApplicationWrapper(IHttpApplication<TContext> 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);
}
}
}
}

View File

@ -6,7 +6,6 @@ using System.IO;
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 @@ namespace Microsoft.AspNetCore.TestHost
}
else
{
#pragma warning disable CS0612 // Type or member is obsolete
webHostBuilder.ConfigureServices(
s => s.AddSingleton<IStartupConfigureServicesFilter>(
new ConfigureTestServicesStartupConfigureServicesFilter(servicesConfiguration)));
#pragma warning restore CS0612 // Type or member is obsolete
}
return webHostBuilder;
@ -81,9 +82,11 @@ namespace Microsoft.AspNetCore.TestHost
throw new ArgumentNullException(nameof(servicesConfiguration));
}
#pragma warning disable CS0612 // Type or member is obsolete
webHostBuilder.ConfigureServices(
s => s.AddSingleton<IStartupConfigureContainerFilter<TContainer>>(
new ConfigureTestServicesStartupConfigureContainerFilter<TContainer>(servicesConfiguration)));
#pragma warning restore CS0612 // Type or member is obsolete
return webHostBuilder;
}
@ -129,7 +132,9 @@ namespace Microsoft.AspNetCore.TestHost
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<IServiceCollection> _servicesConfiguration;
@ -151,7 +156,9 @@ namespace Microsoft.AspNetCore.TestHost
};
}
#pragma warning disable CS0612 // Type or member is obsolete
private class ConfigureTestServicesStartupConfigureContainerFilter<TContainer> : IStartupConfigureContainerFilter<TContainer>
#pragma warning restore CS0612 // Type or member is obsolete
{
private readonly Action<TContainer> _servicesConfiguration;

View File

@ -8,19 +8,17 @@ using System.Net.WebSockets;
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<Context> _application;
private readonly ApplicationWrapper _application;
private readonly PathString _pathBase;
internal WebSocketClient(PathString pathBase, IHttpApplication<Context> application)
internal WebSocketClient(PathString pathBase, ApplicationWrapper application)
{
_application = application ?? throw new ArgumentNullException(nameof(application));

View File

@ -12,12 +12,9 @@ using Microsoft.AspNetCore.Hosting;
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;
using Context = Microsoft.AspNetCore.Hosting.Internal.HostingApplication.Context;
namespace Microsoft.AspNetCore.TestHost
{
@ -421,7 +418,7 @@ namespace Microsoft.AspNetCore.TestHost
HttpCompletionOption.ResponseHeadersRead));
}
private class DummyApplication : IHttpApplication<Context>
private class DummyApplication : ApplicationWrapper, IHttpApplication<TestHostingContext>
{
RequestDelegate _application;
@ -430,26 +427,41 @@ namespace Microsoft.AspNetCore.TestHost
_application = application;
}
public Context CreateContext(IFeatureCollection contextFeatures)
internal override object CreateContext(IFeatureCollection features)
{
return new Context()
return ((IHttpApplication<TestHostingContext>)this).CreateContext(features);
}
TestHostingContext IHttpApplication<TestHostingContext>.CreateContext(IFeatureCollection contextFeatures)
{
return new TestHostingContext()
{
HttpContext = new DefaultHttpContext(contextFeatures)
};
}
public void DisposeContext(Context context, Exception exception)
internal override void DisposeContext(object context, Exception exception)
{
((IHttpApplication<TestHostingContext>)this).DisposeContext((TestHostingContext)context, exception);
}
void IHttpApplication<TestHostingContext>.DisposeContext(TestHostingContext context, Exception exception)
{
}
public Task ProcessRequestAsync(Context context)
internal override Task ProcessRequestAsync(object context)
{
return ((IHttpApplication<TestHostingContext>)this).ProcessRequestAsync((TestHostingContext)context);
}
Task IHttpApplication<TestHostingContext>.ProcessRequestAsync(TestHostingContext context)
{
return _application(context.HttpContext);
}
}
private class InspectingApplication : IHttpApplication<Context>
private class InspectingApplication : ApplicationWrapper, IHttpApplication<TestHostingContext>
{
Action<IFeatureCollection> _inspector;
@ -458,26 +470,46 @@ namespace Microsoft.AspNetCore.TestHost
_inspector = inspector;
}
public Context CreateContext(IFeatureCollection contextFeatures)
internal override object CreateContext(IFeatureCollection features)
{
return ((IHttpApplication<TestHostingContext>)this).CreateContext(features);
}
TestHostingContext IHttpApplication<TestHostingContext>.CreateContext(IFeatureCollection contextFeatures)
{
_inspector(contextFeatures);
return new Context()
return new TestHostingContext()
{
HttpContext = new DefaultHttpContext(contextFeatures)
};
}
public void DisposeContext(Context context, Exception exception)
internal override void DisposeContext(object context, Exception exception)
{
((IHttpApplication<TestHostingContext>)this).DisposeContext((TestHostingContext)context, exception);
}
void IHttpApplication<TestHostingContext>.DisposeContext(TestHostingContext context, Exception exception)
{
}
public Task ProcessRequestAsync(Context context)
internal override Task ProcessRequestAsync(object context)
{
return ((IHttpApplication<TestHostingContext>)this).ProcessRequestAsync((TestHostingContext)context);
}
Task IHttpApplication<TestHostingContext>.ProcessRequestAsync(TestHostingContext context)
{
return Task.FromResult(0);
}
}
private class TestHostingContext
{
public HttpContext HttpContext { get; set; }
}
[Fact]
public async Task ClientHandlerCreateContextWithDefaultRequestParameters()
{

View File

@ -7,13 +7,13 @@ using System.IO;
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 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tests
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<IWebHostEnvironment>(env)
.AddSingleton<IHostEnvironment>(env)
.BuildServiceProvider();
return serverOptions;
@ -462,5 +461,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Tests
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; }
}
}
}