Exemplo n.º 1
0
        public MaxConcurrentRequestsMiddleware(RequestDelegate next, IOptions <MaxConcurrentRequestsOptions> options)
        {
            _concurrentRequestsCount = 0;

            _next    = next ?? throw new ArgumentNullException(nameof(next));
            _options = options?.Value ?? throw new ArgumentNullException(nameof(options));

            if (_options.LimitExceededPolicy != MaxConcurrentRequestsLimitExceededPolicy.Drop)
            {
                _enqueuer = new MaxConcurrentRequestsEnqueuer(_options.MaxQueueLength, (MaxConcurrentRequestsEnqueuer.DropMode)_options.LimitExceededPolicy, _options.MaxTimeInQueue);
            }
        }
Exemplo n.º 2
0
        public static IApplicationBuilder UseMaxConcurrentRequests(this IApplicationBuilder app, Action <MaxConcurrentRequestsOptions> optionsExpression)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            var expr    = optionsExpression ?? delegate { };
            var options = new MaxConcurrentRequestsOptions();

            expr(options);

            return(app.UseMiddleware <MaxConcurrentRequestsMiddleware>(Options.Create(options)));
        }