/// <summary>
        /// Add Graceterm middleware to requests pipeline.
        /// In order to graceterm work properly, you should add it just after log configuration (if you have one), before any other middleware like Mvc, Swagger etc.
        /// </summary>
        /// <param name="applicationBuilder">The applicationBuilder to configure.</param>
        /// <param name="options">User options <see cref="GracetermOptions"/>.</param>
        /// <returns>The applicationBuilder</returns>
        public static IApplicationBuilder UseGraceterm(this IApplicationBuilder applicationBuilder, GracetermOptions options)
        {
            if (options == null)
            {
                options = new GracetermOptions();
            }

            applicationBuilder.UseMiddleware <GracetermMiddleware>(Options.Create(options));

            return(applicationBuilder);
        }
        /// <summary>
        /// Add Graceterm middleware to requests pipeline.
        /// In order to graceterm work properly, you should add it just after log configuration (if you have one), before any other middleware like Mvc, Swagger etc.
        /// </summary>
        /// <param name="applicationBuilder">The applicationBuilder to configure.</param>
        /// <param name="optionsLambda">Convenient way to pass user configuration as lambda <see cref="GracetermOptions"/>.</param>
        /// <returns>The applicationBuilder</returns>
        public static IApplicationBuilder UseGraceterm(this IApplicationBuilder applicationBuilder, Action <GracetermOptions> optionsLambda)
        {
            if (optionsLambda == null)
            {
                throw new ArgumentNullException(nameof(optionsLambda));
            }

            var options = new GracetermOptions();

            optionsLambda.Invoke(options);

            return(UseGraceterm(applicationBuilder, options));
        }
        public LifetimeGracetermService(
            ILoggerFactory loggerFactory,
            IHostApplicationLifetime appLifetime,
            GracetermOptions options)
        {
            logger = loggerFactory?.CreateLogger <LifetimeGracetermService>() ??
                     throw new ArgumentNullException(nameof(loggerFactory));
            this.appLifetime = appLifetime;
            this.options     = options ??
                               throw new ArgumentException(nameof(options));

            appLifetime.ApplicationStopping.Register(OnStopping);
            appLifetime.ApplicationStopped.Register(OnStopped);
        }
Exemple #4
0
        public GracetermMiddleware(RequestDelegate next, ILifetimeGracetermService applicationLifetime,
                                   ILoggerFactory loggerFactory, GracetermOptions options)
        {
            this.next = next ?? throw new ArgumentNullException(nameof(next));
            this.applicationLifetime = applicationLifetime ??
                                       throw new ArgumentNullException(nameof(applicationLifetime));
            logger = loggerFactory?.CreateLogger(LoggerCategory) ??
                     throw new ArgumentNullException(nameof(loggerFactory));
            this.options = options ??
                           throw new ArgumentException(nameof(options));

            if (this.options.CustomPostSigtermRequestsHandler != null)
            {
                postSigtermRequestsHandler = this.options.CustomPostSigtermRequestsHandler;
            }
        }
Exemple #5
0
        public GracetermMiddleware(RequestDelegate next, IApplicationLifetime applicationLifetime, ILoggerFactory loggerFactory, IOptions <GracetermOptions> options)
        {
            _next    = next ?? throw new ArgumentNullException(nameof(next));
            _logger  = loggerFactory?.CreateLogger(LoggerCategory) ?? throw new ArgumentNullException(nameof(loggerFactory));
            _options = options?.Value ?? throw new ArgumentException(nameof(options));

            if (applicationLifetime == null)
            {
                throw new ArgumentNullException(nameof(applicationLifetime));
            }

            if (_options.CustomPostSigtermRequestsHandler != null)
            {
                _postSigtermRequestsHandler = _options.CustomPostSigtermRequestsHandler;
            }

            applicationLifetime.ApplicationStopping.Register(OnApplicationStopping);
            applicationLifetime.ApplicationStopped.Register(OnApplicationStopped);
        }