zhaolei
7 days ago 4a2e5b9a21940f11757be37d99f0944e240e908b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#if !NET45
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System;
 
namespace Prow.Tasks
{
    /// <summary>
    /// 物理文件持久化扩展操作类
    /// </summary>
    public static class FileStorageExtensions
    {
        /// <summary>
        /// 注入物理文件持久化服务到容器内方法
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static ITaskStorageBuilder AddFileStorage(this ITaskStorageBuilder builder, Action<FileStorageOptions>? configure = null)
        {
            builder.Services.AddSingleton<IStorage, FileStorage>();
            builder.Services.AddSingleton<IOptionsChangeTokenSource<FileStorageOptions>, ConfigurationChangeTokenSource<FileStorageOptions>>();
            builder.Services.AddSingleton<IConfigureOptions<FileStorageOptions>, FileStorageOptionsConfigureOptions<FileStorageOptions>>();
            if (configure != null) builder.Services.Configure(configure);
            return builder;
        }
    }
}
#endif