/// <summary>
        /// 添加服务。
        /// </summary>
        /// <typeparam name="TService">服务类型。</typeparam>
        /// <typeparam name="TImplementation">实现服务的类型。</typeparam>
        /// <param name="options">ImageEx 配置项。</param>
        /// <returns>ImageEx 配置项。</returns>
        public static IImageExOptions AddService <TService, TImplementation>([NotNull] this IImageExOptions options) where TService : class where TImplementation : class, TService
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.Services.AddTransient <TService, TImplementation>();
            return(options);
        }
        /// <summary>
        /// 添加管道。
        /// </summary>
        /// <typeparam name="TSource">目标源的类型。</typeparam>
        /// <typeparam name="TPipe">管道类型。</typeparam>
        /// <param name="options">ImageEx 配置项。</param>
        /// <returns>ImageEx 配置项。</returns>
        public static IImageExOptions <TSource> AddPipe <TSource, TPipe>([NotNull] this IImageExOptions <TSource> options) where TSource : class where TPipe : class, ILoadingPipe <TSource>
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.Services.AddTransient <ILoadingPipe <TSource>, TPipe>();
            return(options);
        }
        /// <summary>
        /// 添加服务。
        /// </summary>
        /// <param name="options">ImageEx 配置项。</param>
        /// <param name="serviceType">服务类型。</param>
        /// <returns>ImageEx 配置项。</returns>
        public static IImageExOptions AddService([NotNull] this IImageExOptions options, Type serviceType)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.Services.AddTransient(serviceType);
            return(options);
        }
예제 #4
0
        /// <summary>
        /// 对输出值的类型为 <see cref="ImageSource" /> 使用默认管道。
        /// </summary>
        /// <param name="options">ImageEx 配置项。</param>
        /// <returns>ImageEx 配置项。</returns>
        public static IImageExOptions <ImageSource> WithDefaultPipes([NotNull] this IImageExOptions <ImageSource> options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            ((IImageExOptions)options).WithDefaultPipes();
            options.AddPipe <ImageSource, StreamToImageSourcePipe>();
            return(options);
        }
예제 #5
0
        /// <summary>
        /// 使用默认服务。
        /// </summary>
        /// <param name="options">ImageEx 配置项。</param>
        /// <returns>ImageEx 配置项。</returns>
        public static IImageExOptions WithDefaultServices([NotNull] this IImageExOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.AddService <IDiskCache, DiskCache>();
            options.AddService <IDesignModeService, DesignModeService>();
            //options.UseHttpHandler<HttpClientHandler>();
            return(options);
        }
예제 #6
0
        /// <summary>
        /// 对输出值的类型为字节数组使用默认管道。
        /// </summary>
        /// <param name="options">ImageEx 配置项。</param>
        /// <returns>ImageEx 配置项。</returns>
        public static IImageExOptions <byte[]> WithDefaultPipes([NotNull] this IImageExOptions <byte[]> options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.AddPipe(typeof(MemoryCachePipe <>));
            options.AddPipe(typeof(StringPipe <>));
            options.AddPipe(typeof(DiskCachePipe <>));
            options.AddPipe(typeof(UriPipe <>));
            return(options);
        }
        /// <summary>
        /// 添加管道。
        /// </summary>
        /// <param name="options">ImageEx 配置项。</param>
        /// <param name="pipeType">管道类型。</param>
        /// <returns>ImageEx 配置项。</returns>
        public static IImageExOptions AddPipe([NotNull] this IImageExOptions options, Type pipeType)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (pipeType == null)
            {
                throw new ArgumentNullException(nameof(pipeType));
            }

            options.Services.AddTransient(typeof(ILoadingPipe <>), pipeType);
            return(options);
        }
        /// <summary>
        /// 使用指定的 Http 处理程序。
        /// </summary>
        /// <typeparam name="THandler">Http 处理程序。</typeparam>
        /// <param name="options">ImageEx 配置项。</param>
        /// <returns>ImageEx 配置项。</returns>
        public static IImageExOptions UseHttpHandler <THandler>([NotNull] this IImageExOptions options) where THandler : HttpMessageHandler
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.Services.AddTransient <ThrottlingDelegatingHandler>();
            options.Services.AddTransient <THandler>();
            options.Services.AddHttpClient(Constants.HttpClientName).ConfigureHttpMessageHandlerBuilder(builder =>
            {
                builder.AdditionalHandlers.Add(builder.Services.GetRequiredService <ThrottlingDelegatingHandler>());

                builder.PrimaryHandler = builder.Services.GetRequiredService <THandler>();
            });
            return(options);
        }