Add doc strings for public APIs in src/Hosting (#26443)

* Add doc strings for public APIs in src/Hosting

* Apply suggestions from code review

Co-authored-by: Chris Ross <Tratcher@Outlook.com>
Co-authored-by: Pranav K <prkrishn@hotmail.com>
Co-authored-by: James Newton-King <james@newtonking.com>

* Address feedback from peer review

Co-authored-by: Chris Ross <Tratcher@Outlook.com>
Co-authored-by: Pranav K <prkrishn@hotmail.com>
Co-authored-by: James Newton-King <james@newtonking.com>
This commit is contained in:
Safia Abdalla 2020-09-30 13:42:05 -07:00 committed by GitHub
parent b740b6a23b
commit 66584a0f30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 318 additions and 8 deletions

View File

@ -9,8 +9,19 @@ namespace Microsoft.AspNetCore.Hosting
[System.Obsolete("This type is obsolete and will be removed in a future version. The recommended alternative is Microsoft.Extensions.Hosting.Environments.", error: false)]
public static class EnvironmentName
{
/// <summary>
/// A string constant for Development environments.
/// </summary>
public static readonly string Development = "Development";
/// <summary>
/// A string constant for Staging environments.
/// </summary>
public static readonly string Staging = "Staging";
/// <summary>
/// A string constant for Production environments.
/// </summary>
public static readonly string Production = "Production";
}
}

View File

@ -12,6 +12,9 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Contains extension methods for configuring the <see cref="IWebHostBuilder" />.
/// </summary>
public static class HostingAbstractionsWebHostBuilderExtensions
{
/// <summary>

View File

@ -7,10 +7,21 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Provides an interface for initializing services and middleware used by an application.
/// </summary>
public interface IStartup
{
/// <summary>
/// Register services into the <see cref="IServiceCollection" />.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
IServiceProvider ConfigureServices(IServiceCollection services);
/// <summary>
/// Configures the application.
/// </summary>
/// <param name="app">An <see cref="IApplicationBuilder"/> for the app to configure.</param>
void Configure(IApplicationBuilder app);
}
}
}

View File

@ -12,6 +12,11 @@ namespace Microsoft.AspNetCore.Hosting
[Obsolete]
public interface IStartupConfigureContainerFilter<TContainerBuilder>
{
/// <summary>
/// Extends the provided <paramref name="container"/> and returns a modified <see cref="Action"/> action of the same type.
/// </summary>
/// <param name="container">The ConfigureContainer method to extend.</param>
/// <returns>A modified <see cref="Action"/>.</returns>
Action<TContainerBuilder> ConfigureContainer(Action<TContainerBuilder> container);
}
}

View File

@ -13,6 +13,11 @@ namespace Microsoft.AspNetCore.Hosting
[Obsolete]
public interface IStartupConfigureServicesFilter
{
/// <summary>
/// Extends the provided <paramref name="next"/> and returns a modified <see cref="Action"/> action of the same type.
/// </summary>
/// <param name="next">The ConfigureServices method to extend.</param>
/// <returns>A modified <see cref="Action"/>.</returns>
Action<IServiceCollection> ConfigureServices(Action<IServiceCollection> next);
}
}

View File

@ -6,8 +6,19 @@ using Microsoft.AspNetCore.Builder;
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Provides an interface for extending the middleware pipeline with new
/// Configure methods. Can be used to add defaults to the beginning or
/// end of the pipeline without having to make the app author explicitly
/// register middleware.
/// </summary>
public interface IStartupFilter
{
/// <summary>
/// Extends the provided <paramref name="next"/> and returns an <see cref="Action"/> of the same type.
/// </summary>
/// <param name="next">The Configure method to extend.</param>
/// <returns>A modified <see cref="Action"/>.</returns>
Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next);
}
}

View File

@ -4,7 +4,7 @@
<Description>ASP.NET Core hosting and startup abstractions for web applications.</Description>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<IsAspNetCoreApp>true</IsAspNetCoreApp>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;hosting</PackageTags>
<IsPackable>false</IsPackable>

View File

@ -3,24 +3,85 @@
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Contains a set of constants representing configuration keys.
/// </summary>
public static class WebHostDefaults
{
/// <summary>
/// The configuration key associated with an application name.
/// </summary>
public static readonly string ApplicationKey = "applicationName";
/// <summary>
/// The configuration key associated with the startup assembly.
/// </summary>
public static readonly string StartupAssemblyKey = "startupAssembly";
/// <summary>
/// The configuration key associated with "hostingStartupAssemblies" configuration.
/// </summary>
public static readonly string HostingStartupAssembliesKey = "hostingStartupAssemblies";
/// <summary>
/// The configuration key associated with the "hostingStartupExcludeAssemblies" configuration.
/// </summary>
public static readonly string HostingStartupExcludeAssembliesKey = "hostingStartupExcludeAssemblies";
/// <summary>
/// The configuration key associated with the "DetailedErrors" configuration.
/// </summary>
public static readonly string DetailedErrorsKey = "detailedErrors";
/// <summary>
/// The configuration key associated with the application's environment setting.
/// </summary>
public static readonly string EnvironmentKey = "environment";
/// <summary>
/// The configuration key associated with the "webRoot" configuration.
/// </summary>
public static readonly string WebRootKey = "webroot";
/// <summary>
/// The configuration key associated with the "captureStartupErrors" configuration.
/// </summary>
public static readonly string CaptureStartupErrorsKey = "captureStartupErrors";
/// <summary>
/// The configuration key associated with the "urls" configuration.
/// </summary>
public static readonly string ServerUrlsKey = "urls";
/// <summary>
/// The configuration key associated with the "ContentRoot" configuration.
/// </summary>
public static readonly string ContentRootKey = "contentRoot";
/// <summary>
/// The configuration key associated with the "PreferHostingUrls" configuration.
/// </summary>
public static readonly string PreferHostingUrlsKey = "preferHostingUrls";
/// <summary>
/// The configuration key associated with the "PreventHostingStartup" configuration.
/// </summary>
public static readonly string PreventHostingStartupKey = "preventHostingStartup";
/// <summary>
/// The configuration key associated with the "SuppressStatusMessages" configuration.
/// </summary>
public static readonly string SuppressStatusMessagesKey = "suppressStatusMessages";
/// <summary>
/// The configuration key associated with the "ShutdownTimeoutSeconds" configuration.
/// </summary>
public static readonly string ShutdownTimeoutKey = "shutdownTimeoutSeconds";
/// <summary>
/// The configuration key associated with the "StaticWebAssets" configuration.
/// </summary>
public static readonly string StaticWebAssetsKey = "staticWebAssets";
}
}

View File

@ -9,15 +9,27 @@ using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Hosting.Builder
{
/// <summary>
/// A factory for creating <see cref="IApplicationBuilder" /> instances.
/// </summary>
public class ApplicationBuilderFactory : IApplicationBuilderFactory
{
private readonly IServiceProvider _serviceProvider;
/// <summary>
/// Initialize a new factory instance with an <see cref="IServiceProvider" />.
/// </summary>
/// <param name="serviceProvider">The <see cref="IServiceProvider"/> used to resolve dependencies and initialize components.</param>
public ApplicationBuilderFactory(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
/// <summary>
/// Create an <see cref="IApplicationBuilder" /> builder given a <paramref name="serverFeatures" />.
/// </summary>
/// <param name="serverFeatures">An <see cref="IFeatureCollection"/> of HTTP features.</param>
/// <returns>An <see cref="IApplicationBuilder"/> configured with <paramref name="serverFeatures"/>.</returns>
public IApplicationBuilder CreateBuilder(IFeatureCollection serverFeatures)
{
return new ApplicationBuilder(_serviceProvider, serverFeatures);

View File

@ -6,8 +6,16 @@ using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Hosting.Builder
{
/// <summary>
/// Provides an interface for implementing a factory that produces <see cref="IApplicationBuilder"/> instances.
/// </summary>
public interface IApplicationBuilderFactory
{
/// <summary>
/// Create an <see cref="IApplicationBuilder" /> builder given a <paramref name="serverFeatures" />
/// </summary>
/// <param name="serverFeatures">An <see cref="IFeatureCollection"/> of HTTP features.</param>
/// <returns>An <see cref="IApplicationBuilder"/> configured with <paramref name="serverFeatures"/>.</returns>
IApplicationBuilder CreateBuilder(IFeatureCollection serverFeatures);
}
}
}

View File

@ -7,6 +7,9 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.Extensions.Hosting
{
/// <summary>
/// Contains extensions for an <see cref="IHostBuilder"/>.
/// </summary>
public static class GenericHostWebHostBuilderExtensions
{
/// <summary>

View File

@ -12,6 +12,9 @@ using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Http
{
/// <summary>
/// A factory for creating <see cref="HttpContext" /> instances.
/// </summary>
public class DefaultHttpContextFactory : IHttpContextFactory
{
private readonly IHttpContextAccessor? _httpContextAccessor;
@ -20,6 +23,10 @@ namespace Microsoft.AspNetCore.Http
// This takes the IServiceProvider because it needs to support an ever expanding
// set of services that flow down into HttpContext features
/// <summary>
/// Creates a factory for creating <see cref="HttpContext" /> instances.
/// </summary>
/// <param name="serviceProvider">The <see cref="IServiceProvider"/> to be used when retrieving services.</param>
public DefaultHttpContextFactory(IServiceProvider serviceProvider)
{
// May be null
@ -30,6 +37,11 @@ namespace Microsoft.AspNetCore.Http
internal IHttpContextAccessor? HttpContextAccessor => _httpContextAccessor;
/// <summary>
/// Create an <see cref="HttpContext"/> instance given an <paramref name="featureCollection" />.
/// </summary>
/// <param name="featureCollection"></param>
/// <returns>An initialized <see cref="HttpContext"/> object.</returns>
public HttpContext Create(IFeatureCollection featureCollection)
{
if (featureCollection is null)
@ -67,6 +79,9 @@ namespace Microsoft.AspNetCore.Http
return httpContext;
}
/// <summary>
/// Clears the current <see cref="HttpContext" />.
/// </summary>
public void Dispose(HttpContext httpContext)
{
if (_httpContextAccessor != null)

View File

@ -4,7 +4,7 @@
<Description>ASP.NET Core hosting infrastructure and startup logic for web applications.</Description>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<IsAspNetCoreApp>true</IsAspNetCoreApp>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;hosting</PackageTags>
<IsPackable>false</IsPackable>

View File

@ -7,10 +7,15 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Hosting.Server.Features
{
/// <summary>
/// Specifies the address used by the server.
/// </summary>
public class ServerAddressesFeature : IServerAddressesFeature
{
/// <inheritdoc />
public ICollection<string> Addresses { get; } = new List<string>();
/// <inheritdoc />
public bool PreferHostingUrls { get; set; }
}
}

View File

@ -9,15 +9,27 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Used for initializing services and middlewares used by an application.
/// </summary>
public class DelegateStartup : StartupBase<IServiceCollection>
{
private Action<IApplicationBuilder> _configureApp;
/// <summary>
/// Creates a new <see cref="DelegateStartup" /> instance.
/// </summary>
/// <param name="factory">A factory for creating <see cref="IServiceProvider"/> instances.</param>
/// <param name="configureApp">An <see cref="Action"/> for configuring the application.</param>
public DelegateStartup(IServiceProviderFactory<IServiceCollection> factory, Action<IApplicationBuilder> configureApp) : base(factory)
{
_configureApp = configureApp;
}
/// <summary>
/// Configures the <see cref="IApplicationBuilder"/> with the initialized <see cref="Action"/>.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
public override void Configure(IApplicationBuilder app) => _configureApp(app);
}
}

View File

@ -7,8 +7,15 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Base class for initializing services and middlewares used by an application.
/// </summary>
public abstract class StartupBase : IStartup
{
/// <summary>
/// Configures the application.
/// </summary>
/// <param name="app">An <see cref="IApplicationBuilder"/> for the app to configure.</param>
public abstract void Configure(IApplicationBuilder app);
IServiceProvider IStartup.ConfigureServices(IServiceCollection services)
@ -17,25 +24,47 @@ namespace Microsoft.AspNetCore.Hosting
return CreateServiceProvider(services);
}
/// <summary>
/// Register services into the <see cref="IServiceCollection" />.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
public virtual void ConfigureServices(IServiceCollection services)
{
}
/// <summary>
/// Creates an <see cref="IServiceProvider" /> instance for a given <see cref="ConfigureServices(IServiceCollection)" />.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
/// <returns>The <see cref="IServiceProvider"/>.</returns>
public virtual IServiceProvider CreateServiceProvider(IServiceCollection services)
{
return services.BuildServiceProvider();
}
}
/// <summary>
/// Base class for initializing services and middlewares used for configuring a <typeparamref name="TBuilder"/>.
/// </summary>
/// <typeparam name="TBuilder">The type of builder associated with the startup configuration.</typeparam>
public abstract class StartupBase<TBuilder> : StartupBase
{
private readonly IServiceProviderFactory<TBuilder> _factory;
/// <summary>
/// Constructor for StartupBase class.
/// </summary>
/// <param name="factory">A factory used to generate <see cref="IServiceProvider"/> instances.</param>
public StartupBase(IServiceProviderFactory<TBuilder> factory)
{
_factory = factory;
}
/// <summary>
/// Creates an <see cref="IServiceProvider" /> instance for a given <see cref="IServiceCollection" />.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
/// <returns>The <see cref="IServiceProvider"/>.</returns>
public override IServiceProvider CreateServiceProvider(IServiceCollection services)
{
var builder = _factory.CreateBuilder(services);
@ -43,8 +72,12 @@ namespace Microsoft.AspNetCore.Hosting
return _factory.CreateServiceProvider(builder);
}
/// <summary>
/// Sets up the service container.
/// </summary>
/// <param name="builder">The builder associated with the container to configure.</param>
public virtual void ConfigureContainer(TBuilder builder)
{
}
}
}
}

View File

@ -17,6 +17,9 @@ using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Contains extensions for configuring an <see cref="IWebHostBuilder" />.
/// </summary>
public static class WebHostBuilderExtensions
{
/// <summary>

View File

@ -12,6 +12,9 @@ using Microsoft.Extensions.Hosting;
namespace Microsoft.AspNetCore.Hosting
{
/// <summary>
/// Contains extensions for managing the lifecycle of an <see cref="IWebHost"/>.
/// </summary>
public static class WebHostExtensions
{
/// <summary>

View File

@ -5,10 +5,19 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Hosting.Server.Features
{
/// <summary>
/// Specifies the address used by the server.
/// </summary>
public interface IServerAddressesFeature
{
/// <summary>
/// An <see cref="ICollection{T}" /> of addresses used by the server.
/// </summary>
ICollection<string> Addresses { get; }
/// <summary>
/// <see langword="true" /> to prefer URLs configured by the host rather than the server.
/// </summary>
bool PreferHostingUrls { get; set; }
}
}

View File

@ -10,6 +10,9 @@ namespace Microsoft.AspNetCore.Hosting.Server.Abstractions
/// <typeparam name="TContext">The <see cref="IHttpApplication{TContext}"/> Host context</typeparam>
public interface IHostContextContainer<TContext> where TContext : notnull
{
/// <summary>
/// Represents the <typeparamref name="TContext"/> of the host.
/// </summary>
TContext HostContext { get; set; }
}
}

View File

@ -4,7 +4,7 @@
<Description>ASP.NET Core hosting server abstractions for web applications.</Description>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<IsAspNetCoreApp>true</IsAspNetCoreApp>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;hosting</PackageTags>
<IsPackable>false</IsPackable>

View File

@ -10,6 +10,9 @@ using Microsoft.Extensions.Hosting;
namespace Microsoft.AspNetCore.TestHost
{
/// <summary>
/// Contains extensions for retrieving properties from <see cref="IHost"/>.
/// </summary>
public static class HostBuilderTestServerExtensions
{
/// <summary>

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<Description>ASP.NET Core web server for writing and running tests.</Description>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;hosting;testing</PackageTags>
</PropertyGroup>

View File

@ -13,6 +13,9 @@ using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.TestHost
{
/// <summary>
/// An <see cref="IServer"/> implementation for executing tests.
/// </summary>
public class TestServer : IServer
{
private IWebHost _hostInstance;
@ -69,8 +72,14 @@ namespace Microsoft.AspNetCore.TestHost
Services = host.Services;
}
/// <summary>
/// Gets or sets the base address associated with the HttpClient returned by the test server. Defaults to http://localhost/.
/// </summary>
public Uri BaseAddress { get; set; } = new Uri("http://localhost/");
/// <summary>
/// Gets the <see cref="IWebHost" /> instance associated with the test server.
/// </summary>
public IWebHost Host
{
get
@ -80,8 +89,14 @@ namespace Microsoft.AspNetCore.TestHost
}
}
/// <summary>
/// Gets the service provider associated with the test server.
/// </summary>
public IServiceProvider Services { get; }
/// <summary>
/// Gets the collection of server features associated with the test server.
/// </summary>
public IFeatureCollection Features { get; }
/// <summary>
@ -99,17 +114,26 @@ namespace Microsoft.AspNetCore.TestHost
get => _application ?? throw new InvalidOperationException("The server has not been started or no web application was configured.");
}
/// <summary>
/// Creates a custom <see cref="HttpMessageHandler" /> for processing HTTP requests/responses with the test server.
/// </summary>
public HttpMessageHandler CreateHandler()
{
var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress);
return new ClientHandler(pathBase, Application) { AllowSynchronousIO = AllowSynchronousIO, PreserveExecutionContext = PreserveExecutionContext };
}
/// <summary>
/// Creates a <see cref="HttpClient" /> for processing HTTP requests/responses with the test server.
/// </summary>
public HttpClient CreateClient()
{
return new HttpClient(CreateHandler()) { BaseAddress = BaseAddress };
}
/// <summary>
/// Creates a <see cref="WebSocketClient" /> for interacting with the test server.
/// </summary>
public WebSocketClient CreateWebSocketClient()
{
var pathBase = BaseAddress == null ? PathString.Empty : PathString.FromUriComponent(BaseAddress);
@ -159,6 +183,9 @@ namespace Microsoft.AspNetCore.TestHost
return await builder.SendAsync(cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Dispoes the <see cref="IWebHost" /> object associated with the test server.
/// </summary>
public void Dispose()
{
if (!_disposed)

View File

@ -13,8 +13,16 @@ using Microsoft.Extensions.Hosting;
namespace Microsoft.AspNetCore.TestHost
{
/// <summary>
/// Contains extensions for configuring the <see cref="IWebHostBuilder" /> instance.
/// </summary>
public static class WebHostBuilderExtensions
{
/// <summary>
/// Enables the <see cref="TestServer" /> service.
/// </summary>
/// <param name="builder">The <see cref="IWebHostBuilder"/>.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
public static IWebHostBuilder UseTestServer(this IWebHostBuilder builder)
{
return builder.ConfigureServices(services =>
@ -44,6 +52,12 @@ namespace Microsoft.AspNetCore.TestHost
return host.GetTestServer().CreateClient();
}
/// <summary>
/// Configures the <see cref="IWebHostBuilder" /> instance with the services provided in <paramref name="servicesConfiguration" />.
/// </summary>
/// <param name="webHostBuilder">The <see cref="IWebHostBuilder"/>.</param>
/// <param name="servicesConfiguration">An <see cref="Action"/> that registers services onto the <see cref="IServiceCollection"/>.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
public static IWebHostBuilder ConfigureTestServices(this IWebHostBuilder webHostBuilder, Action<IServiceCollection> servicesConfiguration)
{
if (webHostBuilder == null)
@ -73,6 +87,13 @@ namespace Microsoft.AspNetCore.TestHost
return webHostBuilder;
}
/// <summary>
/// Configures the <see cref="IWebHostBuilder" /> instance with the services provided in <paramref name="servicesConfiguration" />.
/// </summary>
/// <param name="webHostBuilder">The <see cref="IWebHostBuilder"/>.</param>
/// <param name="servicesConfiguration">An <see cref="Action"/> that registers services onto the <typeparamref name="TContainer"/>.</param>
/// <typeparam name="TContainer">A collection of service descriptors.</typeparam>
/// <returns></returns>
public static IWebHostBuilder ConfigureTestContainer<TContainer>(this IWebHostBuilder webHostBuilder, Action<TContainer> servicesConfiguration)
{
if (webHostBuilder == null)
@ -94,6 +115,13 @@ namespace Microsoft.AspNetCore.TestHost
return webHostBuilder;
}
/// <summary>
/// Sets the content root of relative to the <paramref name="solutionRelativePath" />.
/// </summary>
/// <param name="builder">The <see cref="IWebHostBuilder"/>.</param>
/// <param name="solutionRelativePath">The directory of the solution file.</param>
/// <param name="solutionName">The name of the solution file to make the content root relative to.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
[SuppressMessage("ApiDesign", "RS0026:Do not add multiple public overloads with optional parameters", Justification = "Required to maintain compatibility")]
public static IWebHostBuilder UseSolutionRelativeContentRoot(
this IWebHostBuilder builder,
@ -103,6 +131,14 @@ namespace Microsoft.AspNetCore.TestHost
return builder.UseSolutionRelativeContentRoot(solutionRelativePath, AppContext.BaseDirectory, solutionName);
}
/// <summary>
/// Sets the content root of relative to the <paramref name="solutionRelativePath" />.
/// </summary>
/// <param name="builder">The <see cref="IWebHostBuilder"/>.</param>
/// <param name="solutionRelativePath">The directory of the solution file.</param>
/// <param name="applicationBasePath">The root of the app's directory.</param>
/// <param name="solutionName">The name of the solution file to make the content root relative to.</param>
/// <returns>The <see cref="IWebHostBuilder"/>.</returns>
[SuppressMessage("ApiDesign", "RS0026:Do not add multiple public overloads with optional parameters", Justification = "Required to maintain compatibility")]
public static IWebHostBuilder UseSolutionRelativeContentRoot(
this IWebHostBuilder builder,

View File

@ -7,14 +7,29 @@ using Microsoft.Extensions.Hosting;
namespace Microsoft.AspNetCore.TestHost
{
/// <summary>
/// A factory for creating <see cref="IWebHostBuilder" /> instances.
/// </summary>
public static class WebHostBuilderFactory
{
/// <summary>
/// Resolves an <see cref="IWebHostBuilder" /> defined in the entry point of an assembly.
/// </summary>
/// <param name="assembly">The assembly to look for an <see cref="IWebHostBuilder"/> in.</param>
/// <param name="args">The arguments to use when creating the <see cref="IWebHostBuilder"/> instance.</param>
/// <returns>An <see cref="IWebHostBuilder"/> instance retrieved from the assembly in <paramref name="assembly"/>.</returns>
public static IWebHostBuilder CreateFromAssemblyEntryPoint(Assembly assembly, string[] args)
{
var factory = HostFactoryResolver.ResolveWebHostBuilderFactory<IWebHostBuilder>(assembly);
return factory?.Invoke(args);
}
/// <summary>
/// Resolves an <see cref="IWebHostBuilder" /> defined in an assembly where <typeparamref name="T"/> is declared.
/// </summary>
/// <param name="args">The arguments to use when creating the <see cref="IWebHostBuilder"/> instance.</param>
/// <typeparam name="T">Type contained in the target assembly</typeparam>
/// <returns>An <see cref="IWebHostBuilder"/> instance retrieved from the assembly.</returns>
public static IWebHostBuilder CreateFromTypesAssemblyEntryPoint<T>(string[] args) =>
CreateFromAssemblyEntryPoint(typeof(T).Assembly, args);
}

View File

@ -15,6 +15,9 @@ using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.TestHost
{
/// <summary>
/// Provides a client for connecting over WebSockets to a test server.
/// </summary>
public class WebSocketClient
{
private readonly ApplicationWrapper _application;
@ -34,12 +37,18 @@ namespace Microsoft.AspNetCore.TestHost
SubProtocols = new List<string>();
}
/// <summary>
/// Gets the list of WebSocket subprotocols that are established in the initial handshake.
/// </summary>
public IList<string> SubProtocols
{
get;
private set;
}
/// <summary>
/// Gets or sets the handler used to configure the outgoing request to the WebSocket endpoint.
/// </summary>
public Action<HttpRequest> ConfigureRequest
{
get;
@ -49,6 +58,11 @@ namespace Microsoft.AspNetCore.TestHost
internal bool AllowSynchronousIO { get; set; }
internal bool PreserveExecutionContext { get; set; }
/// <summary>
/// Establishes a WebSocket connection to an endpoint.
/// </summary>
/// <param name="uri">The <see cref="Uri" /> of the endpoint.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to terminate the connection.</param>
public async Task<WebSocket> ConnectAsync(Uri uri, CancellationToken cancellationToken)
{
WebSocketFeature webSocketFeature = null;

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<Description>ASP.NET Core hosting infrastructure and startup logic for web applications running within a Windows service.</Description>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;hosting</PackageTags>
</PropertyGroup>

View File

@ -33,6 +33,7 @@ namespace Microsoft.AspNetCore.Hosting.WindowsServices
/// </summary>
internal void Start() => OnStart(Array.Empty<string>());
/// <inheritdoc />
protected sealed override void OnStart(string[] args)
{
OnStarting(args);
@ -57,6 +58,7 @@ namespace Microsoft.AspNetCore.Hosting.WindowsServices
});
}
/// <inheritdoc />
protected sealed override void OnStop()
{
_stopRequestedByWindows = true;