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" >
2
2
<PropertyGroup >
3
- <Version >0.2.0</ Version >
3
+ <PackageId >aliyun.sdk.oss</ PackageId >
4
4
<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 >
7
6
<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 >
10
9
</PropertyGroup >
11
10
<ItemGroup >
12
11
<Folder Include =" Properties\" />
13
12
</ItemGroup >
14
13
<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" />
17
17
</ItemGroup >
18
18
</Project >
Original file line number Diff line number Diff line change @@ -19,9 +19,7 @@ public class BucketInfo
19
19
/// <summary>
20
20
/// 是否https访问方式
21
21
/// </summary>
22
- public bool IsHttps { get ; private set ; }
23
-
24
-
22
+ public bool IsHttps { get ; private set ; }
25
23
26
24
/// <summary>
27
25
/// Bucket名称
@@ -36,13 +34,10 @@ public class BucketInfo
36
34
/// <summary>
37
35
/// 带有bucket网址的uri
38
36
/// </summary>
39
- public Uri BucketUri { get ; private set ; }
40
-
41
-
37
+ public Uri BucketUri { get ; private set ; }
42
38
43
39
private BucketInfo ( )
44
- {
45
- }
40
+ { }
46
41
47
42
/// <summary>
48
43
/// 使用自定义域名创建地址信息
Original file line number Diff line number Diff line change @@ -15,9 +15,7 @@ namespace Cuiliang.AliyunOssSdk.Entites
15
15
public class ClientConfiguration
16
16
{
17
17
private const string UserAgentPrefix = "aliyun-sdk-dotnet/" ;
18
- private static readonly string _userAgent = GetDefaultUserAgent ( ) ;
19
-
20
-
18
+ private static readonly string _userAgent = GetDefaultUserAgent ( ) ;
21
19
22
20
/// <summary>
23
21
/// HttpWebRequest最大的并发连接数目。
@@ -67,9 +65,7 @@ public string UserAgent
67
65
/// <summary>
68
66
/// 获取或设置请求发生错误时最大的重试次数。
69
67
/// </summary>
70
- public int MaxErrorRetry { get ; set ; } = 3 ;
71
-
72
-
68
+ public int MaxErrorRetry { get ; set ; } = 3 ;
73
69
74
70
/// <summary>
75
71
/// <para>设置自定义基准时间。</para>
@@ -93,7 +89,6 @@ public void SetCustomEpochTicks(long epochTicks)
93
89
/// </summary>
94
90
public long TickOffset { get ; internal set ; }
95
91
96
-
97
92
/// <summary>
98
93
/// 默认配置
99
94
/// </summary>
@@ -103,7 +98,6 @@ public static ClientConfiguration Default {
103
98
return new ClientConfiguration ( ) ;
104
99
}
105
100
}
106
-
107
101
108
102
/// <summary>
109
103
/// 获取User-Agent信息。
Original file line number Diff line number Diff line change 1
- using System ;
1
+ using Microsoft . Extensions . Options ;
2
+ using System ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
using System . Threading . Tasks ;
@@ -8,7 +9,7 @@ namespace Cuiliang.AliyunOssSdk.Entites
8
9
/// <summary>
9
10
/// Oss访问安全凭据
10
11
/// </summary>
11
- public class OssCredential
12
+ public class OssCredential : IOptions < OssCredential >
12
13
{
13
14
public string AccessKeyId { get ; set ; }
14
15
public string AccessKeySecret { get ; set ; }
@@ -24,5 +25,6 @@ public bool UseToken {
24
25
/// 令牌
25
26
/// </summary>
26
27
public string SecurityToken { get ; set ; }
28
+ public OssCredential Value => this ;
27
29
}
28
30
}
Original file line number Diff line number Diff line change @@ -24,7 +24,6 @@ public class OssRegions
24
24
public const string HuHeHaoTe = "oss-cn-huhehaote" ;
25
25
26
26
27
-
28
27
// 华南 1
29
28
public const string ShenZhen = "oss-cn-shenzhen" ;
30
29
Original file line number Diff line number Diff line change 2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
4
using System . Linq ;
5
+ using System . Net ;
5
6
using System . Net . Http ;
6
7
using System . Threading . Tasks ;
7
8
using 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 3
3
using System . Linq ;
4
4
using System . Threading . Tasks ;
5
5
using Cuiliang . AliyunOssSdk . Entites ;
6
+ using Microsoft . Extensions . Options ;
6
7
7
8
namespace Cuiliang . AliyunOssSdk . Request
8
9
{
@@ -11,9 +12,9 @@ namespace Cuiliang.AliyunOssSdk.Request
11
12
/// </summary>
12
13
public class RequestContext
13
14
{
14
- public RequestContext ( OssCredential credential , ClientConfiguration config )
15
+ public RequestContext ( IOptions < OssCredential > credentialOptions , ClientConfiguration config )
15
16
{
16
- OssCredential = credential ;
17
+ OssCredential = credentialOptions . Value ;
17
18
ClientConfiguration = config ;
18
19
}
19
20
/// <summary>
Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ namespace Cuiliang.AliyunOssSdk.Request
16
16
/// </summary>
17
17
public class ServiceCaller
18
18
{
19
- private readonly static HttpClient _client = new HttpClient ( ) ;
20
19
private RequestContext _requestContext ;
21
20
private readonly HttpClient _client ;
22
21
You can’t perform that action at this time.
0 commit comments