Revert "Revert "React to hosting changes""

This reverts commit 12649b19bf.
This commit is contained in:
David Fowler 2016-12-14 00:01:35 -08:00
parent 12649b19bf
commit df9057a6f7
2 changed files with 5 additions and 11 deletions

View File

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

View File

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