public static IServiceCollection AddGracefullShutdown(this IServiceCollection services) { var state = new GracefullShutdownState(); services.AddSingleton(state); services.AddSingleton <IRequestsCountProvider>(state); var options = new GracefullShutdownOptions(); services.AddSingleton(options); return(services); }
public GracefullShutdownMiddleware( RequestDelegate next, GracefullShutdownOptions options, IApplicationLifetime applicationLifetime, ILogger <GracefullShutdownMiddleware> logger, GracefullShutdownState state ) { if (applicationLifetime == null) { throw new ArgumentNullException(nameof(applicationLifetime)); } _next = next ?? throw new ArgumentNullException(nameof(next)); _options = options ?? throw new ArgumentNullException(nameof(options)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _state = state ?? throw new ArgumentNullException(nameof(state)); applicationLifetime.ApplicationStopping.Register(OnApplicationStopping); }