File tree Expand file tree Collapse file tree 13 files changed +114
-248
lines changed
Expand file tree Collapse file tree 13 files changed +114
-248
lines changed Original file line number Diff line number Diff line change 1- <Project Sdk =" Microsoft.NET.Sdk" ToolsVersion =" 15.0" >
1+ <Project Sdk =" Microsoft.NET.Sdk" ToolsVersion =" 15.0" >
22 <PropertyGroup >
3- <Version >0.2.0</ Version >
3+ <PackageId >aliyun.sdk.oss</ PackageId >
44 <TargetFramework >netstandard2.0</TargetFramework >
5- <Authors >cuiliang.bj@gmail.com</Authors >
6- <Description >Aliyun oss sdk for dotnet core.</Description >
5+ <Description >Aliyun OSS SDK for .NET Core</Description >
76 <PackageTags >Aliyun</PackageTags >
8- <RepositoryUrl >https://github.com/cuiliang/ Cuiliang.AliyunOssSdk</ RepositoryUrl >
9- <GeneratePackageOnBuild >true</ GeneratePackageOnBuild >
7+ <Authors > Cuiliang</ Authors >
8+ <PackageProjectUrl >https://github.com/cnblogs/Cuiliang.AliyunOssSdk</ PackageProjectUrl >
109 </PropertyGroup >
1110 <ItemGroup >
1211 <Folder Include =" Properties\" />
1312 </ItemGroup >
1413 <ItemGroup >
15- <PackageReference Include =" Microsoft.Extensions.DependencyInjection.Abstractions" Version =" 2.1.0" />
16- <PackageReference Include =" Microsoft.Extensions.Http" Version =" 2.1.0" />
14+ <PackageReference Include =" Microsoft.Extensions.DependencyInjection.Abstractions" Version =" 2.1.1" />
15+ <PackageReference Include =" Microsoft.Extensions.Http" Version =" 2.1.1" />
16+ <PackageReference Include =" Microsoft.Extensions.Options.ConfigurationExtensions" Version =" 2.1.1" />
1717 </ItemGroup >
1818</Project >
Original file line number Diff line number Diff line change @@ -19,9 +19,7 @@ public class BucketInfo
1919 /// <summary>
2020 /// 是否https访问方式
2121 /// </summary>
22- public bool IsHttps { get ; private set ; }
23-
24-
22+ public bool IsHttps { get ; private set ; }
2523
2624 /// <summary>
2725 /// Bucket名称
@@ -36,13 +34,10 @@ public class BucketInfo
3634 /// <summary>
3735 /// 带有bucket网址的uri
3836 /// </summary>
39- public Uri BucketUri { get ; private set ; }
40-
41-
37+ public Uri BucketUri { get ; private set ; }
4238
4339 private BucketInfo ( )
44- {
45- }
40+ { }
4641
4742 /// <summary>
4843 /// 使用自定义域名创建地址信息
Original file line number Diff line number Diff line change @@ -15,9 +15,7 @@ namespace Cuiliang.AliyunOssSdk.Entites
1515 public class ClientConfiguration
1616 {
1717 private const string UserAgentPrefix = "aliyun-sdk-dotnet/" ;
18- private static readonly string _userAgent = GetDefaultUserAgent ( ) ;
19-
20-
18+ private static readonly string _userAgent = GetDefaultUserAgent ( ) ;
2119
2220 /// <summary>
2321 /// HttpWebRequest最大的并发连接数目。
@@ -67,9 +65,7 @@ public string UserAgent
6765 /// <summary>
6866 /// 获取或设置请求发生错误时最大的重试次数。
6967 /// </summary>
70- public int MaxErrorRetry { get ; set ; } = 3 ;
71-
72-
68+ public int MaxErrorRetry { get ; set ; } = 3 ;
7369
7470 /// <summary>
7571 /// <para>设置自定义基准时间。</para>
@@ -93,7 +89,6 @@ public void SetCustomEpochTicks(long epochTicks)
9389 /// </summary>
9490 public long TickOffset { get ; internal set ; }
9591
96-
9792 /// <summary>
9893 /// 默认配置
9994 /// </summary>
@@ -103,7 +98,6 @@ public static ClientConfiguration Default {
10398 return new ClientConfiguration ( ) ;
10499 }
105100 }
106-
107101
108102 /// <summary>
109103 /// 获取User-Agent信息。
Original file line number Diff line number Diff line change 1- using System ;
1+ using Microsoft . Extensions . Options ;
2+ using System ;
23using System . Collections . Generic ;
34using System . Linq ;
45using System . Threading . Tasks ;
@@ -8,7 +9,7 @@ namespace Cuiliang.AliyunOssSdk.Entites
89 /// <summary>
910 /// Oss访问安全凭据
1011 /// </summary>
11- public class OssCredential
12+ public class OssCredential : IOptions < OssCredential >
1213 {
1314 public string AccessKeyId { get ; set ; }
1415 public string AccessKeySecret { get ; set ; }
@@ -24,5 +25,6 @@ public bool UseToken {
2425 /// 令牌
2526 /// </summary>
2627 public string SecurityToken { get ; set ; }
28+ public OssCredential Value => this ;
2729 }
2830}
Original file line number Diff line number Diff line change @@ -24,7 +24,6 @@ public class OssRegions
2424 public const string HuHeHaoTe = "oss-cn-huhehaote" ;
2525
2626
27-
2827 // 华南 1
2928 public const string ShenZhen = "oss-cn-shenzhen" ;
3029
Original file line number Diff line number Diff line change 22using System . Collections . Generic ;
33using System . IO ;
44using System . Linq ;
5+ using System . Net ;
56using System . Net . Http ;
67using System . Threading . Tasks ;
78using Cuiliang . AliyunOssSdk . Api ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Net . Http ;
3+ using Cuiliang . AliyunOssSdk ;
4+ using Cuiliang . AliyunOssSdk . Api . Bucket . List ;
5+ using Cuiliang . AliyunOssSdk . Entites ;
6+ using Cuiliang . AliyunOssSdk . Request ;
7+ using Microsoft . Extensions . Configuration ;
8+ using Microsoft . Extensions . DependencyInjection ;
9+
10+ namespace Microsoft . Extensions . DependencyInjection
11+ {
12+ public static class OssClientServiceCollectionExtensions
13+ {
14+ public static IServiceCollection AddOssClient (
15+ this IServiceCollection services ,
16+ IConfiguration configuration ,
17+ string sectionName = "ossClient" ,
18+ Action < ClientConfiguration > setupClientConfiguration = null ,
19+ Action < HttpClient > configureHttpClient = null )
20+ {
21+ services . Configure < OssCredential > ( configuration . GetSection ( "ossClient" ) ) ;
22+
23+ var clientConfiguration = new ClientConfiguration ( ) ;
24+ setupClientConfiguration ? . Invoke ( clientConfiguration ) ;
25+ services . AddSingleton ( clientConfiguration ) ;
26+
27+ services . AddTransient < RequestContext > ( ) ;
28+
29+ if ( configureHttpClient == null )
30+ {
31+ services . AddHttpClient < OssClient > ( ) ;
32+ }
33+ else
34+ {
35+ services . AddHttpClient < OssClient > ( configureHttpClient ) ;
36+ }
37+
38+ return services ;
39+ }
40+ }
41+ }
Original file line number Diff line number Diff line change 33using System . Linq ;
44using System . Threading . Tasks ;
55using Cuiliang . AliyunOssSdk . Entites ;
6+ using Microsoft . Extensions . Options ;
67
78namespace Cuiliang . AliyunOssSdk . Request
89{
@@ -11,9 +12,9 @@ namespace Cuiliang.AliyunOssSdk.Request
1112 /// </summary>
1213 public class RequestContext
1314 {
14- public RequestContext ( OssCredential credential , ClientConfiguration config )
15+ public RequestContext ( IOptions < OssCredential > credentialOptions , ClientConfiguration config )
1516 {
16- OssCredential = credential ;
17+ OssCredential = credentialOptions . Value ;
1718 ClientConfiguration = config ;
1819 }
1920 /// <summary>
Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ namespace Cuiliang.AliyunOssSdk.Request
1616 /// </summary>
1717 public class ServiceCaller
1818 {
19- private readonly static HttpClient _client = new HttpClient ( ) ;
2019 private RequestContext _requestContext ;
2120 private readonly HttpClient _client ;
2221
You can’t perform that action at this time.
0 commit comments