@@ -11,34 +11,17 @@ namespace Cuiliang.AliyunOssSdk
1111 public static class OssClientExtensions
1212 {
1313 public static IServiceCollection AddOssClient ( this IServiceCollection services ,
14- Action < OssCredential > optionsAction ,
15- ClientConfiguration config = null )
14+ IConfigurationSection ossClientConf , ClientConfiguration config = null )
1615 {
17-
1816 var credential = new OssCredential ( ) ;
19- optionsAction ? . Invoke ( credential ) ;
17+ ossClientConf . Bind ( credential ) ;
18+
2019 var requestContext = new RequestContext ( credential , config ?? ClientConfiguration . Default ) ;
2120
2221 services . AddSingleton < RequestContext > ( requestContext ) ;
2322 services . AddHttpClient < OssClient > ( ) ;
2423
2524 return services ;
2625 }
27-
28- public static IServiceCollection AddOssClient ( this IServiceCollection services ,
29- IConfigurationSection ossClientConf ,
30- ClientConfiguration config = null )
31- {
32- var ossClientOptions = new OssClientOptions ( ) ;
33- ossClientConf . Bind ( ossClientOptions ) ;
34-
35- return
36- AddOssClient ( services , options =>
37- {
38- options . AccessKeyId = ossClientOptions . AccessKeyId ;
39- options . AccessKeySecret = ossClientOptions . AccessKeySecret ;
40- options . SecurityToken = ossClientOptions . SecurityToken ;
41- } , config ) ;
42- }
4326 }
4427}
0 commit comments