Esempio n. 1
0
        /// <summary>
        /// Registers watch-dog middleware using <paramref name="builder"/>.
        /// </summary>
        /// <param name="builder">The builder to use for registration.</param>
        /// <param name="options">The watch-dog configuration.</param>
        /// <returns><paramref name="builder"/></returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="builder"/> or <paramref name="options"/> is null.
        /// </exception>
        public static IRegistrar <IRequestProcessorMiddleware> AddWatchDog(this IRegistrar <IRequestProcessorMiddleware> builder, Action <WatchDogOptions> configureOptions)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var options = OptionsBuilder.ConfigureAndValidate(configureOptions);

            return(builder.Add(ctx => new WatchDogMiddleware(options, ctx.GetLogger())));
        }
Esempio n. 2
0
        /// <summary>
        /// Registers throttling middleware using <paramref name="builder"/> with the specified <paramref name="options"/>.
        /// </summary>
        /// <param name="builder">The builder to use for registration.</param>
        /// <param name="options">The throttling configuration.</param>
        /// <returns><paramref name="builder"/></returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="builder"/> or <paramref name="options"/> is null.
        /// </exception>
        public static IRegistrar <IRequestProcessorMiddleware> AddThrottling(this IRegistrar <IRequestProcessorMiddleware> builder, Action <ThrottleOptions> configureOptions)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (configureOptions == null)
            {
                throw new ArgumentNullException(nameof(configureOptions));
            }

            var options = OptionsBuilder.ConfigureAndValidate(configureOptions);

            return(builder.Add(ctx => new ThrottleMiddleware(options)));
        }