diff --git a/src/Storage/Masa.Contrib.Storage.ObjectStorage.Aliyun/ServiceCollectionExtensions.cs b/src/Storage/Masa.Contrib.Storage.ObjectStorage.Aliyun/ServiceCollectionExtensions.cs index 1532d2372..594d4e0fc 100644 --- a/src/Storage/Masa.Contrib.Storage.ObjectStorage.Aliyun/ServiceCollectionExtensions.cs +++ b/src/Storage/Masa.Contrib.Storage.ObjectStorage.Aliyun/ServiceCollectionExtensions.cs @@ -41,7 +41,7 @@ public static IServiceCollection AddAliyunStorage(this IServiceCollection servic return services.AddAliyunStorage(() => options); } - public static IServiceCollection AddAliyunStorage(this IServiceCollection services, Func func) + public static IServiceCollection AddAliyunStorage(this IServiceCollection services, Func func) { ArgumentNullException.ThrowIfNull(func, nameof(func)); @@ -49,16 +49,23 @@ public static IServiceCollection AddAliyunStorage(this IServiceCollection servic services.TryAddSingleton(); services.TryAddSingleton(serviceProvider => new DefaultCredentialProvider( GetOssClientFactory(serviceProvider), - func.Invoke(), + func.Invoke(serviceProvider), GetMemoryCache(serviceProvider), GetDefaultCredentialProviderLogger(serviceProvider))); services.TryAddSingleton(serviceProvider => new Client( GetCredentialProvider(serviceProvider), - func.Invoke(), + func.Invoke(serviceProvider), GetClientLogger(serviceProvider))); return services; } + public static IServiceCollection AddAliyunStorage(this IServiceCollection services, Func func) + { + ArgumentNullException.ThrowIfNull(func, nameof(func)); + + return services.AddAliyunStorage(_ => func.Invoke()); + } + private static IServiceCollection AddAliyunStorageDepend(this IServiceCollection services) { services.AddMemoryCache(); @@ -113,7 +120,8 @@ private static void CheckAliYunStorageOptions(AliyunStorageOptions options) ArgumentNullException.ThrowIfNull(options, nameof(options)); if (options.AccessKeyId == null && options.AccessKeySecret == null) - throw new ArgumentException($"{nameof(options.AccessKeyId)}, {nameof(options.AccessKeySecret)} are required and cannot be empty"); + throw new ArgumentException( + $"{nameof(options.AccessKeyId)}, {nameof(options.AccessKeySecret)} are required and cannot be empty"); ObjectStorageExtensions.CheckNullOrEmptyAndReturnValue(options.AccessKeyId, nameof(options.AccessKeyId)); ObjectStorageExtensions.CheckNullOrEmptyAndReturnValue(options.AccessKeySecret, nameof(options.AccessKeySecret));