React to hosting changes

This commit is contained in:
David Fowler 2016-12-13 23:03:20 -08:00
parent 46cf13b2fc
commit f48bd8d185
2 changed files with 5 additions and 11 deletions

View File

@ -6,26 +6,20 @@ using Microsoft.AspNetCore.Hosting;
namespace Microsoft.AspNetCore.Sockets namespace Microsoft.AspNetCore.Sockets
{ {
public class SocketsApplicationLifetimeEvents : IApplicationLifetimeEvents public class SocketsApplicationLifetimeService : IHostedService
{ {
private readonly ConnectionManager _connectionManager; private readonly ConnectionManager _connectionManager;
public SocketsApplicationLifetimeEvents(ConnectionManager connectionManager) public SocketsApplicationLifetimeService(ConnectionManager connectionManager)
{ {
_connectionManager = connectionManager; _connectionManager = connectionManager;
} }
public void OnApplicationStarted() public void Start()
{ {
} }
public void OnApplicationStopped() public void Stop()
{
}
public void OnApplicationStopping()
{ {
_connectionManager.CloseConnections(); _connectionManager.CloseConnections();
} }

View File

@ -14,7 +14,7 @@ namespace Microsoft.Extensions.DependencyInjection
{ {
services.AddRouting(); services.AddRouting();
services.TryAddSingleton<ConnectionManager>(); services.TryAddSingleton<ConnectionManager>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<IApplicationLifetimeEvents, SocketsApplicationLifetimeEvents>()); services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, SocketsApplicationLifetimeService>());
services.TryAddSingleton<PipelineFactory>(); services.TryAddSingleton<PipelineFactory>();
services.TryAddSingleton<HttpConnectionDispatcher>(); services.TryAddSingleton<HttpConnectionDispatcher>();
return services; return services;