public static void Configure <T>(Action <ImageExOptions <T> > configure) where T : class
        {
            var options = new ImageExOptions <T>();

            configure(options);

            Services[typeof(T)] = options.Services;
        }
Пример #2
0
        /// <summary>
        /// 进行配置。
        /// </summary>
        /// <typeparam name="TSource">目标源的类型。</typeparam>
        /// <param name="configure">执行配置的委托。</param>
        public static void Configure <TSource>(Action <IImageExOptions <TSource> > configure) where TSource : class
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var options = new ImageExOptions <TSource>();

            configure(options);

            if (_throttler == null || _throttlerInitialCount != options.MaxHttpDownloadCount)
            {
                _throttler             = new SemaphoreSlim(options.MaxHttpDownloadCount);
                _throttlerInitialCount = options.MaxHttpDownloadCount;
            }

            options.Services.AddSingleton(_throttler);
            Services[typeof(TSource)] = options.Services;
        }