Add synchronous Start back to IWebHost (#1125)

* Add synchronous Start back to IWebHost
- Fixed extension methods to have a default(CancellationToken)
- Removed extension methods for Start, StartAsync and StopAsync
This commit is contained in:
David Fowler 2017-07-01 15:00:54 -07:00 committed by GitHub
parent b8e699b844
commit b0a70aeef7
4 changed files with 17 additions and 43 deletions

View File

@ -26,13 +26,18 @@ namespace Microsoft.AspNetCore.Hosting
/// <summary> /// <summary>
/// Starts listening on the configured addresses. /// Starts listening on the configured addresses.
/// </summary> /// </summary>
Task StartAsync(CancellationToken cancellationToken); void Start();
/// <summary>
/// Starts listening on the configured addresses.
/// </summary>
Task StartAsync(CancellationToken cancellationToken = default(CancellationToken));
/// <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); Task StopAsync(CancellationToken cancellationToken = default(CancellationToken));
} }
} }

View File

@ -1,9 +1,4 @@
[ [
{
"TypeId": "public interface Microsoft.AspNetCore.Hosting.IWebHost : System.IDisposable",
"MemberId": "System.Void Start()",
"Kind": "Removal"
},
{ {
"TypeId": "public interface Microsoft.AspNetCore.Hosting.IWebHostBuilder", "TypeId": "public interface Microsoft.AspNetCore.Hosting.IWebHostBuilder",
"MemberId": "Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureAppConfiguration(System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.Extensions.Configuration.IConfigurationBuilder> configureDelegate)", "MemberId": "Microsoft.AspNetCore.Hosting.IWebHostBuilder ConfigureAppConfiguration(System.Action<Microsoft.AspNetCore.Hosting.WebHostBuilderContext, Microsoft.Extensions.Configuration.IConfigurationBuilder> configureDelegate)",
@ -16,12 +11,12 @@
}, },
{ {
"TypeId": "public interface Microsoft.AspNetCore.Hosting.IWebHost : System.IDisposable", "TypeId": "public interface Microsoft.AspNetCore.Hosting.IWebHost : System.IDisposable",
"MemberId": "System.Threading.Tasks.Task StartAsync(System.Threading.CancellationToken cancellationToken)", "MemberId": "System.Threading.Tasks.Task StartAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))",
"Kind": "Addition" "Kind": "Addition"
}, },
{ {
"TypeId": "public interface Microsoft.AspNetCore.Hosting.IWebHost : System.IDisposable", "TypeId": "public interface Microsoft.AspNetCore.Hosting.IWebHost : System.IDisposable",
"MemberId": "System.Threading.Tasks.Task StopAsync(System.Threading.CancellationToken cancellationToken)", "MemberId": "System.Threading.Tasks.Task StopAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))",
"Kind": "Addition" "Kind": "Addition"
}, },
{ {

View File

@ -104,7 +104,12 @@ namespace Microsoft.AspNetCore.Hosting.Internal
} }
} }
public virtual async Task StartAsync(CancellationToken cancellationToken) public void Start()
{
StartAsync().GetAwaiter().GetResult();
}
public virtual async Task StartAsync(CancellationToken cancellationToken = default(CancellationToken))
{ {
HostingEventSource.Log.HostStart(); HostingEventSource.Log.HostStart();
_logger = _applicationServices.GetRequiredService<ILogger<WebHost>>(); _logger = _applicationServices.GetRequiredService<ILogger<WebHost>>();
@ -267,7 +272,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
} }
} }
public async Task StopAsync(CancellationToken cancellationToken) public async Task StopAsync(CancellationToken cancellationToken = default(CancellationToken))
{ {
if (_stopped) if (_stopped)
{ {
@ -313,7 +318,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
{ {
try try
{ {
this.StopAsync().GetAwaiter().GetResult(); StopAsync().GetAwaiter().GetResult();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -2,7 +2,6 @@
// 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; using System;
using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Hosting.Server.Features;
@ -12,36 +11,6 @@ namespace Microsoft.AspNetCore.Hosting
{ {
public static class WebHostExtensions public static class WebHostExtensions
{ {
/// <summary>
/// Starts the host.
/// </summary>
/// <param name="host"></param>
/// <returns></returns>
public static void Start(this IWebHost host)
{
host.StartAsync().GetAwaiter().GetResult();
}
/// <summary>
/// Starts the host.
/// </summary>
/// <param name="host"></param>
/// <returns></returns>
public static Task StartAsync(this IWebHost host)
{
return host.StartAsync(CancellationToken.None);
}
/// <summary>
/// Gracefully stops the host.
/// </summary>
/// <param name="host"></param>
/// <returns></returns>
public static Task StopAsync(this IWebHost host)
{
return host.StopAsync(CancellationToken.None);
}
/// <summary> /// <summary>
/// Attempts to gracefully stop the host with the given timeout. /// Attempts to gracefully stop the host with the given timeout.
/// </summary> /// </summary>