예제 #1
0
        /// <summary>
        /// 添加OSS功能
        /// </summary>
        /// <param name="services"></param>
        /// <param name="cfg"></param>
        /// <returns></returns>
        public static IServiceCollection AddOSS(this IServiceCollection services, IConfiguration cfg)
        {
            var config  = new OSSConfig();
            var section = cfg.GetSection("OSS");

            if (section != null)
            {
                section.Bind(config);
            }

            services.AddSingleton(config);

            var assembly = AssemblyHelper.LoadByNameEndString($".Lib.OSS.{config.Provider.ToString()}");

            Check.NotNull(assembly, $"OSS实现程序集({config.Provider.ToString()})未找到,请安装 NetModular.Lib.OSS.{config.Provider.ToString()} 包");

            var providerType = assembly.GetTypes().FirstOrDefault(m => typeof(IFileStorageProvider).IsAssignableFrom(m));

            if (providerType != null)
            {
                services.AddSingleton(typeof(IFileStorageProvider), providerType);
            }

            return(services);
        }
예제 #2
0
 public MinioHelper(OSSConfig config)
 {
     _client = new MinioClient(config.Minio.Endpoint,
                               config.Minio.AccessKey,
                               config.Minio.SecretKey
                               );
 }
예제 #3
0
        /// <summary>
        /// 添加OSS功能
        /// </summary>
        /// <param name="services"></param>
        /// <param name="cfg"></param>
        /// <returns></returns>
        public static IServiceCollection AddOSS(this IServiceCollection services, IConfiguration cfg)
        {
            var config = new OSSConfig();
            // 从appsetting.json中读取
            var section = cfg.GetSection("OSS");

            if (section != null)
            {
                // 配置数据绑定实体类
                section.Bind(config);
            }

            // 如果未启用oss服务
            if (!config.IsEnabled)
            {
                return(services);
            }

            if (config.Aliyun != null && config.Aliyun.Domain.NotNull() && !config.Aliyun.Domain.EndsWith("/"))
            {
                config.Aliyun.Domain += "/";
            }

            services.AddSingleton(config);

            var assembly = AssemblyHelper.LoadByNameEndString($"OSS.{config.Provider}");

            if (assembly == null)
            {
                return(services);
            }

            var providerType = assembly.GetTypes().FirstOrDefault(m => typeof(IFileStorageProvider).IsAssignableFrom(m));

            if (providerType != null)
            {
                services.AddSingleton(typeof(IFileStorageProvider), providerType);
            }

            return(services);
        }
 public AliyunFileStorageProvider(AliyunHelper helper, OSSConfig config)
 {
     _helper = helper;
     _config = config.Aliyun;
 }
예제 #5
0
 public AliyunHelper(OSSConfig config, ILogger <AliyunHelper> logger)
 {
     _logger = logger;
     _config = config.Aliyun;
 }
예제 #6
0
 public MinioHelper(OSSConfig config, ILogger <MinioHelper> logger)
 {
     _logger = logger;
     _config = config.Minio;
 }
 public MinioFileStorageProvider(MinioHelper helper, OSSConfig config)
 {
     _helper     = helper;
     _minoConfig = config.Minio;
 }
예제 #8
0
 public QiniuTokenManager(OSSConfig config)
 {
     _config = config.Qiniu;
     RefreshTimer();
 }
예제 #9
0
 public QiniuFileStorageProvider(QiniuHelper helper, OSSConfig config)
 {
     _helper = helper;
     _config = config.Qiniu;
 }
예제 #10
0
 public QiniuHelper(QiniuTokenManager tokenManager, ILogger <QiniuHelper> logger, OSSConfig config)
 {
     _tokenManager = tokenManager;
     _logger       = logger;
     _config       = config.Qiniu;
 }