コード例 #1
0
        /// <summary>
        ///     If no decompression providers are specified then all is used by default.
        /// </summary>
        /// <param name="services">Services to use when instantiating decompression providers.</param>
        /// <param name="options">The options for this instance.</param>
        public RequestDecompressionProvider(IServiceProvider services, RequestDecompressionOptions options)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _providers = options.Providers.ToArray();

            // If no decompression providers are specified then all is used by default
            if (_providers.Length == 0)
            {
                _providers = GetAllAvailableDecompressionProviders();
            }
            else
            {
                for (int i = 0; i < _providers.Length; i++)
                {
                    var factory = _providers[i] as DecompressionProviderFactory;
                    if (factory != null)
                    {
                        _providers[i] = factory.CreateInstance(services);
                    }
                }
            }

            _logger = services.GetRequiredService <ILogger <RequestDecompressionProvider> >();
        }
コード例 #2
0
        public static IHoneyCombBuilder AddRequestDecompression(this IHoneyCombBuilder builder, Action <RequestDecompressionOptions> configureOptions = null)
        {
            var options = new RequestDecompressionOptions();

            configureOptions?.Invoke(options);

            builder.Services.AddSingleton(options);
            builder.Services.AddSingleton <IRequestDecompressionProvider, RequestDecompressionProvider>();

            return(builder);
        }