Misc generic host pr feedback (#1222)

This commit is contained in:
Chris Ross 2017-09-21 15:09:52 -07:00 committed by GitHub
parent e53abdb2b8
commit 253be73b6f
13 changed files with 25 additions and 26 deletions

View File

@ -31,7 +31,7 @@ namespace GenericHostSample
public void RegisterDelayStartCallback(Action<object> callback, object state) public void RegisterDelayStartCallback(Action<object> callback, object state)
{ {
_startCallback = callback ?? throw new ArgumentNullException(nameof(callback)); _startCallback = callback ?? throw new ArgumentNullException(nameof(callback));
_startState = state ?? throw new ArgumentNullException(nameof(state)); _startState = state;
Run(this); Run(this);
} }
@ -39,7 +39,7 @@ namespace GenericHostSample
public void RegisterStopCallback(Action<object> callback, object state) public void RegisterStopCallback(Action<object> callback, object state)
{ {
_stopCallback = callback ?? throw new ArgumentNullException(nameof(callback)); _stopCallback = callback ?? throw new ArgumentNullException(nameof(callback));
_stopState = state ?? throw new ArgumentNullException(nameof(state)); _stopState = state;
} }
public Task StopAsync(CancellationToken cancellationToken) public Task StopAsync(CancellationToken cancellationToken)

View File

@ -31,13 +31,13 @@ namespace Microsoft.AspNetCore.Hosting
/// <summary> /// <summary>
/// Starts listening on the configured addresses. /// Starts listening on the configured addresses.
/// </summary> /// </summary>
Task StartAsync(CancellationToken cancellationToken = default(CancellationToken)); Task StartAsync(CancellationToken cancellationToken = default);
/// <summary> /// <summary>
/// Attempt to gracefully stop the host. /// Attempt to gracefully stop the host.
/// </summary> /// </summary>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
Task StopAsync(CancellationToken cancellationToken = default(CancellationToken)); Task StopAsync(CancellationToken cancellationToken = default);
} }
} }

View File

@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
StartAsync().GetAwaiter().GetResult(); StartAsync().GetAwaiter().GetResult();
} }
public virtual async Task StartAsync(CancellationToken cancellationToken = default(CancellationToken)) public virtual async Task StartAsync(CancellationToken cancellationToken = default)
{ {
HostingEventSource.Log.HostStart(); HostingEventSource.Log.HostStart();
_logger = _applicationServices.GetRequiredService<ILogger<WebHost>>(); _logger = _applicationServices.GetRequiredService<ILogger<WebHost>>();
@ -282,7 +282,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
} }
} }
public async Task StopAsync(CancellationToken cancellationToken = default(CancellationToken)) public async Task StopAsync(CancellationToken cancellationToken = default)
{ {
if (_stopped) if (_stopped)
{ {

View File

@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Hosting
/// </summary> /// </summary>
/// <param name="host">The running <see cref="IWebHost"/>.</param> /// <param name="host">The running <see cref="IWebHost"/>.</param>
/// <param name="token">The token to trigger shutdown.</param> /// <param name="token">The token to trigger shutdown.</param>
public static async Task WaitForShutdownAsync(this IWebHost host, CancellationToken token = default(CancellationToken)) public static async Task WaitForShutdownAsync(this IWebHost host, CancellationToken token = default)
{ {
var done = new ManualResetEventSlim(false); var done = new ManualResetEventSlim(false);
using (var cts = CancellationTokenSource.CreateLinkedTokenSource(token)) using (var cts = CancellationTokenSource.CreateLinkedTokenSource(token))
@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Hosting
/// </summary> /// </summary>
/// <param name="host">The <see cref="IWebHost"/> to run.</param> /// <param name="host">The <see cref="IWebHost"/> to run.</param>
/// <param name="token">The token to trigger shutdown.</param> /// <param name="token">The token to trigger shutdown.</param>
public static async Task RunAsync(this IWebHost host, CancellationToken token = default(CancellationToken)) public static async Task RunAsync(this IWebHost host, CancellationToken token = default)
{ {
// Wait for token shutdown if it can be canceled // Wait for token shutdown if it can be canceled
if (token.CanBeCanceled) if (token.CanBeCanceled)

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
public static async Task<HttpResponseMessage> RetryRequest( public static async Task<HttpResponseMessage> RetryRequest(
Func<Task<HttpResponseMessage>> retryBlock, Func<Task<HttpResponseMessage>> retryBlock,
ILogger logger, ILogger logger,
CancellationToken cancellationToken = default(CancellationToken), CancellationToken cancellationToken = default,
int retryCount = 60) int retryCount = 60)
{ {
for (var retry = 0; retry < retryCount; retry++) for (var retry = 0; retry < retryCount; retry++)

View File

@ -8,7 +8,7 @@ namespace Microsoft.Extensions.Hosting
public static class HostingAbstractionsHostBuilderExtensions public static class HostingAbstractionsHostBuilderExtensions
{ {
/// <summary> /// <summary>
/// Start the web host and listen on the specified urls. /// Start the host and listen on the specified urls.
/// </summary> /// </summary>
/// <param name="hostBuilder">The <see cref="IHostBuilder"/> to start.</param> /// <param name="hostBuilder">The <see cref="IHostBuilder"/> to start.</param>
/// <returns>The <see cref="IHostBuilder"/>.</returns> /// <returns>The <see cref="IHostBuilder"/>.</returns>

View File

@ -41,7 +41,7 @@ namespace Microsoft.Extensions.Hosting
} }
/// <summary> /// <summary>
/// Runs a web application and block the calling thread until host shutdown. /// Runs an application and block the calling thread until host shutdown.
/// </summary> /// </summary>
/// <param name="host">The <see cref="IHost"/> to run.</param> /// <param name="host">The <see cref="IHost"/> to run.</param>
public static void Run(this IHost host) public static void Run(this IHost host)
@ -50,11 +50,11 @@ namespace Microsoft.Extensions.Hosting
} }
/// <summary> /// <summary>
/// Runs a web application and returns a Task that only completes when the token is triggered or shutdown is triggered. /// Runs an application and returns a Task that only completes when the token is triggered or shutdown is triggered.
/// </summary> /// </summary>
/// <param name="host">The <see cref="IHost"/> to run.</param> /// <param name="host">The <see cref="IHost"/> to run.</param>
/// <param name="token">The token to trigger shutdown.</param> /// <param name="token">The token to trigger shutdown.</param>
public static async Task RunAsync(this IHost host, CancellationToken token = default(CancellationToken)) public static async Task RunAsync(this IHost host, CancellationToken token = default)
{ {
using (host) using (host)
{ {
@ -69,7 +69,7 @@ namespace Microsoft.Extensions.Hosting
/// </summary> /// </summary>
/// <param name="host">The running <see cref="IHost"/>.</param> /// <param name="host">The running <see cref="IHost"/>.</param>
/// <param name="token">The token to trigger shutdown.</param> /// <param name="token">The token to trigger shutdown.</param>
public static async Task WaitForShutdownAsync(this IHost host, CancellationToken token = default(CancellationToken)) public static async Task WaitForShutdownAsync(this IHost host, CancellationToken token = default)
{ {
var applicationLifetime = host.Services.GetService<IApplicationLifetime>(); var applicationLifetime = host.Services.GetService<IApplicationLifetime>();
@ -88,7 +88,7 @@ namespace Microsoft.Extensions.Hosting
await waitForStop.Task; await waitForStop.Task;
// WebHost will use its default ShutdownTimeout if none is specified. // Host will use its default ShutdownTimeout if none is specified.
await host.StopAsync(); await host.StopAsync();
} }
} }

View File

@ -22,13 +22,13 @@ namespace Microsoft.Extensions.Hosting
/// </summary> /// </summary>
/// <param name="cancellationToken">Used to abort program start.</param> /// <param name="cancellationToken">Used to abort program start.</param>
/// <returns></returns> /// <returns></returns>
Task StartAsync(CancellationToken cancellationToken = default(CancellationToken)); Task StartAsync(CancellationToken cancellationToken = default);
/// <summary> /// <summary>
/// Attempts to gracefully stop the program. /// Attempts to gracefully stop the program.
/// </summary> /// </summary>
/// <param name="cancellationToken">Used to indicate when stop should no longer be graceful.</param> /// <param name="cancellationToken">Used to indicate when stop should no longer be graceful.</param>
/// <returns></returns> /// <returns></returns>
Task StopAsync(CancellationToken cancellationToken = default(CancellationToken)); Task StopAsync(CancellationToken cancellationToken = default);
} }
} }

View File

@ -1,13 +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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
namespace Microsoft.Extensions.Hosting namespace Microsoft.Extensions.Hosting
{ {
/// <summary> /// <summary>
/// Provides information about the web hosting environment an application is running in. /// Provides information about the hosting environment an application is running in.
/// </summary> /// </summary>
public interface IHostingEnvironment public interface IHostingEnvironment
{ {

View File

@ -178,7 +178,7 @@ namespace Microsoft.Extensions.Hosting
services.AddSingleton(_hostBuilderContext); services.AddSingleton(_hostBuilderContext);
services.AddSingleton(_appConfiguration); services.AddSingleton(_appConfiguration);
services.AddSingleton<IApplicationLifetime, ApplicationLifetime>(); services.AddSingleton<IApplicationLifetime, ApplicationLifetime>();
services.AddSingleton<IHostLifetime, HostProcessLifetime>(); services.AddSingleton<IHostLifetime, ProcessLifetime>();
services.AddOptions(); services.AddOptions();
services.AddLogging(); services.AddLogging();

View File

@ -15,7 +15,7 @@ namespace Microsoft.Extensions.Hosting
public static class HostingHostBuilderExtensions public static class HostingHostBuilderExtensions
{ {
/// <summary> /// <summary>
/// Specify the environment to be used by the web host. /// Specify the environment to be used by the host.
/// </summary> /// </summary>
/// <param name="hostBuilder">The <see cref="IHostBuilder"/> to configure.</param> /// <param name="hostBuilder">The <see cref="IHostBuilder"/> to configure.</param>
/// <param name="environment">The environment to host the application in.</param> /// <param name="environment">The environment to host the application in.</param>
@ -33,7 +33,7 @@ namespace Microsoft.Extensions.Hosting
} }
/// <summary> /// <summary>
/// Specify the content root directory to be used by the web host. /// Specify the content root directory to be used by the host.
/// </summary> /// </summary>
/// <param name="hostBuilder">The <see cref="IHostBuilder"/> to configure.</param> /// <param name="hostBuilder">The <see cref="IHostBuilder"/> to configure.</param>
/// <param name="contentRoot">Path to root directory of the application.</param> /// <param name="contentRoot">Path to root directory of the application.</param>
@ -125,7 +125,7 @@ namespace Microsoft.Extensions.Hosting
/// <param name="hostBuilder">The <see cref="IHostBuilder" /> to configure.</param> /// <param name="hostBuilder">The <see cref="IHostBuilder" /> to configure.</param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
public static Task RunConsoleAsync(this IHostBuilder hostBuilder, CancellationToken cancellationToken = default(CancellationToken)) public static Task RunConsoleAsync(this IHostBuilder hostBuilder, CancellationToken cancellationToken = default)
{ {
return hostBuilder.UseConsoleLifetime().Build().RunAsync(cancellationToken); return hostBuilder.UseConsoleLifetime().Build().RunAsync(cancellationToken);
} }

View File

@ -28,7 +28,7 @@ namespace Microsoft.Extensions.Hosting.Internal
public IServiceProvider Services { get; } public IServiceProvider Services { get; }
public async Task StartAsync(CancellationToken cancellationToken = default(CancellationToken)) public async Task StartAsync(CancellationToken cancellationToken = default)
{ {
_logger.Starting(); _logger.Starting();
@ -53,7 +53,7 @@ namespace Microsoft.Extensions.Hosting.Internal
_logger.Started(); _logger.Started();
} }
public async Task StopAsync(CancellationToken cancellationToken = default(CancellationToken)) public async Task StopAsync(CancellationToken cancellationToken = default)
{ {
_logger.Stopping(); _logger.Stopping();

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Microsoft.Extensions.Hosting.Internal namespace Microsoft.Extensions.Hosting.Internal
{ {
public class HostProcessLifetime : IHostLifetime public class ProcessLifetime : IHostLifetime
{ {
public void RegisterDelayStartCallback(Action<object> callback, object state) public void RegisterDelayStartCallback(Action<object> callback, object state)
{ {