Skip to content

Commit 6f9e52c

Browse files
authored
Merge pull request #25 from cnblogs/translate-documentations
docs: translate xml document of Cnblogs.Architecture.Ddd.Cqrs.Abstractions
2 parents 0b35b4d + 842a53d commit 6f9e52c

38 files changed

+218
-186
lines changed

Cnblogs.Architecture.sln.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=cachable/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<Product>Cnblogs.Architecture</Product>
99
<PackageProjectUrl>https://github.com/cnblogs/Architecture</PackageProjectUrl>
1010
<PackageLicenseExpression>MIT</PackageLicenseExpression>
11+
<RepositoryUrl>https://github.com/cnblogs/Architecture</RepositoryUrl>
12+
<RepositoryType>git</RepositoryType>
1113
</PropertyGroup>
1214

1315
<ItemGroup>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
namespace Cnblogs.Architecture.Ddd.Cqrs.Abstractions;
22

33
/// <summary>
4-
/// 缓存行为定义。
4+
/// Options for handing <see cref="ICachableRequest"/>.
55
/// </summary>
66
public enum CacheBehavior
77
{
88
/// <summary>
9-
/// 不存在时获取新的。
9+
/// Update cache after cache missed, this is the default behavior.
1010
/// </summary>
1111
UpdateCacheIfMiss = 1,
1212

1313
/// <summary>
14-
/// 不使用缓存。
14+
/// Do not cache this request.
1515
/// </summary>
1616
DisabledCache = 2
1717
}

src/Cnblogs.Architecture.Ddd.Cqrs.Abstractions/CacheableRequestBehavior.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
namespace Cnblogs.Architecture.Ddd.Cqrs.Abstractions;
1010

1111
/// <summary>
12-
/// 对实现了 <see cref="ICacheableRequest" /> 的请求进行处理。
12+
/// Handler for <see cref="ICachableRequest" />.
1313
/// </summary>
14-
/// <typeparam name="TRequest">实现了 <see cref="ICacheableRequest" /> 的请求。</typeparam>
15-
/// <typeparam name="TResponse"><typeparamref name="TRequest" /> 请求的结果。</typeparam>
14+
/// <typeparam name="TRequest">Request that implements <see cref="ICachableRequest" />.</typeparam>
15+
/// <typeparam name="TResponse">Cached result for <typeparamref name="TRequest" />.</typeparam>
1616
public class CacheableRequestBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
17-
where TRequest : ICacheableRequest, IRequest<TResponse>
17+
where TRequest : ICachableRequest, IRequest<TResponse>
1818
{
1919
private readonly IDateTimeProvider _dateTimeProvider;
2020
private readonly ILocalCacheProvider? _local;
@@ -23,12 +23,12 @@ public class CacheableRequestBehavior<TRequest, TResponse> : IPipelineBehavior<T
2323
private readonly ILogger<CacheableRequestBehavior<TRequest, TResponse>> _logger;
2424

2525
/// <summary>
26-
/// 构建一个 <see cref="CacheableRequestBehavior{TRequest,TResponse}" />
26+
/// Create <see cref="CacheableRequestBehavior{TRequest,TResponse}" />.
2727
/// </summary>
28-
/// <param name="providers">缓存提供器。</param>
29-
/// <param name="dateTimeProvider">时间提供器。</param>
30-
/// <param name="options">缓存配置项。</param>
31-
/// <param name="logger">日志记录器。</param>
28+
/// <param name="providers">Cache providers.</param>
29+
/// <param name="dateTimeProvider">Datetime provider.</param>
30+
/// <param name="options">Options for cache behavior.</param>
31+
/// <param name="logger">logger.</param>
3232
public CacheableRequestBehavior(
3333
IEnumerable<ICacheProvider> providers,
3434
IDateTimeProvider dateTimeProvider,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
namespace Cnblogs.Architecture.Ddd.Cqrs.Abstractions;
22

33
/// <summary>
4-
/// 缓存配置。
4+
/// Options for handling <see cref="ICachableRequest"/>.
55
/// </summary>
66
public class CacheableRequestOptions
77
{
88
/// <summary>
9-
/// 如果获取失败抛出异常。
9+
/// Rethrow exception if getting cached result failed.
1010
/// </summary>
1111
public bool ThrowIfFailedOnGet { get; set; }
1212

1313
/// <summary>
14-
/// 如果更新失败则抛出异常。
14+
/// Rethrow exception if updating cache failed.
1515
/// </summary>
1616
public bool ThrowIfFailedOnUpdate { get; set; }
1717

1818
/// <summary>
19-
/// 如果清除缓存失败则抛出异常,可能被 <see cref="InvalidCacheRequest"/> 中的 <see cref="InvalidCacheRequest.ThrowIfFailed"/> 覆盖。
19+
/// Rethrow exception if removing cache failed, this option can be overriden by <see cref="InvalidCacheRequest.ThrowIfFailed"/> for specific type of request.
2020
/// </summary>
2121
public bool ThrowIfFailedOnRemove { get; set; }
2222
}
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<ItemGroup>
4-
<ProjectReference Include="..\Cnblogs.Architecture.Ddd.Infrastructure.Abstractions\Cnblogs.Architecture.Ddd.Infrastructure.Abstractions.csproj" />
5-
</ItemGroup>
6-
7-
<ItemGroup>
8-
<PackageReference Include="Mapster" Version="7.3.0" />
9-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
10-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
11-
</ItemGroup>
3+
<PropertyGroup>
4+
<Description>
5+
Provides building blocks to archive CQRS pattern, including ICommand, IQuery, IPageableQuery, etc.
6+
</Description>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\Cnblogs.Architecture.Ddd.Infrastructure.Abstractions\Cnblogs.Architecture.Ddd.Infrastructure.Abstractions.csproj"/>
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Mapster" Version="7.3.0"/>
15+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0"/>
16+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0"/>
17+
</ItemGroup>
1218

1319
</Project>

src/Cnblogs.Architecture.Ddd.Cqrs.Abstractions/CommandResponse.cs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33
namespace Cnblogs.Architecture.Ddd.Cqrs.Abstractions;
44

55
/// <summary>
6-
/// 命令返回的结果。
6+
/// Response returned by <see cref="ICommand{TError}"/>.
77
/// </summary>
88
public abstract record CommandResponse : IValidationResponse, ILockableResponse
99
{
1010
/// <summary>
11-
/// 是否出现验证错误。
11+
/// Check if validation fails.
1212
/// </summary>
1313
public bool IsValidationError { get; init; }
1414

1515
/// <summary>
16-
/// 是否出现并发错误。
16+
/// Check if concurrent error happened.
1717
/// </summary>
1818
public bool IsConcurrentError { get; init; }
1919

2020
/// <summary>
21-
/// 错误信息。
21+
/// The error message returned by handler, return empty if no error or no error message.
2222
/// </summary>
23+
/// <remarks>
24+
/// Do not rely on this property to determine if executed successful, use <see cref="IsSuccess"/> for this purpose.
25+
/// </remarks>
2326
public string ErrorMessage { get; init; } = string.Empty;
2427

2528
/// <inheritdoc />
@@ -29,55 +32,55 @@ public abstract record CommandResponse : IValidationResponse, ILockableResponse
2932
public bool LockAcquired { get; set; }
3033

3134
/// <summary>
32-
/// 执行是否成功。
35+
/// Check if command executed successfully.
3336
/// </summary>
34-
/// <returns></returns>
37+
/// <returns>Return true if executed successfully, else return false.</returns>
3538
public virtual bool IsSuccess()
3639
{
3740
return IsValidationError == false && string.IsNullOrEmpty(ErrorMessage) && IsConcurrentError == false;
3841
}
3942

4043
/// <summary>
41-
/// 获取错误信息。
44+
/// Get error message.
4245
/// </summary>
43-
/// <returns></returns>
46+
/// <returns>The error message, return <see cref="string.Empty"/> if no error.</returns>
4447
public virtual string GetErrorMessage() => ErrorMessage;
4548
}
4649

4750
/// <summary>
48-
/// 命令返回的结果。
51+
/// Response returned by <see cref="ICommand{TError}"/>.
4952
/// </summary>
50-
/// <typeparam name="TError">错误枚举类型。</typeparam>
53+
/// <typeparam name="TError">The enumeration presenting errors.</typeparam>
5154
public record CommandResponse<TError> : CommandResponse
5255
where TError : Enumeration
5356
{
5457
/// <summary>
55-
/// 构造一个 <see cref="CommandResponse{TError}" />
58+
/// Create a successful <see cref="CommandResponse{TError}" />.
5659
/// </summary>
5760
public CommandResponse()
5861
{
5962
ErrorCode = default;
6063
}
6164

6265
/// <summary>
63-
/// 构造一个 <see cref="CommandResponse{TError}" />
66+
/// Create a <see cref="CommandResponse{TError}" /> with given error.
6467
/// </summary>
65-
/// <param name="errorCode">错误码。</param>
68+
/// <param name="errorCode">The error.</param>
6669
public CommandResponse(TError errorCode)
6770
{
6871
ErrorCode = errorCode;
6972
}
7073

7174
/// <summary>
72-
/// 错误码。
75+
/// The error returned by handler, can be null if execution succeeded.
7376
/// </summary>
7477
public TError? ErrorCode { get; set; }
7578

7679
/// <summary>
77-
/// 构造一个代表命令执行失败的 <see cref="CommandResponse{TError}" />
80+
/// Create a failed <see cref="CommandResponse{TError}" /> with given error.
7881
/// </summary>
79-
/// <param name="errorCode">错误码。</param>
80-
/// <returns>代表命令执行失败的 <see cref="CommandResponse{TError}" /></returns>
82+
/// <param name="errorCode">The error.</param>
83+
/// <returns>A failed <see cref="CommandResponse{TError}" /> with given error.</returns>
8184
public static CommandResponse<TError> Fail(TError errorCode)
8285
{
8386
return new CommandResponse<TError>(errorCode);
@@ -96,77 +99,80 @@ public override string GetErrorMessage()
9699
}
97100

98101
/// <summary>
99-
/// 构造一个代表命令执行成功的 <see cref="CommandResponse{TError}" />
102+
/// Create a successful <see cref="CommandResponse{TError}" />.
100103
/// </summary>
101-
/// <returns>代表命令执行成功的 <see cref="CommandResponse{TError}" /></returns>
104+
/// <returns>A successful <see cref="CommandResponse{TError}" />.</returns>
102105
public static CommandResponse<TError> Success()
103106
{
104107
return new CommandResponse<TError>();
105108
}
106109
}
107110

108111
/// <summary>
109-
/// 命令返回的结果。
112+
/// Response returned by <see cref="ICommand{TError}"/>.
110113
/// </summary>
111-
/// <typeparam name="TView">命令执行成功时返回的结果类型。</typeparam>
112-
/// <typeparam name="TError">错误类型。</typeparam>
114+
/// <typeparam name="TView">The model type been returned if execution completed without error.</typeparam>
115+
/// <typeparam name="TError">The enumeration type representing errors.</typeparam>
113116
public record CommandResponse<TView, TError> : CommandResponse<TError>, IObjectResponse
114117
where TError : Enumeration
115118
{
116119
/// <summary>
117-
/// 构造一个 <see cref="CommandResponse{TView,TError}" />
120+
/// Create a <see cref="CommandResponse{TView,TError}" />.
118121
/// </summary>
119122
public CommandResponse()
120123
{
121124
}
122125

123126
/// <summary>
124-
/// 构造一个 <see cref="CommandResponse{TError}" />
127+
/// Create a <see cref="CommandResponse{TError}" /> with given error.
125128
/// </summary>
126-
/// <param name="errorCode">错误码。</param>
129+
/// <param name="errorCode">The error.</param>
127130
public CommandResponse(TError errorCode)
128131
: base(errorCode)
129132
{
130133
}
131134

132135
/// <summary>
133-
/// 构造一个 <see cref="CommandResponse{TError}" />
136+
/// Create a <see cref="CommandResponse{TError}" /> with given model.
134137
/// </summary>
135-
/// <param name="response">命令返回结果。</param>
138+
/// <param name="response">The execution result.</param>
136139
private CommandResponse(TView response)
137140
{
138141
Response = response;
139142
}
140143

141144
/// <summary>
142-
/// 命令执行结果。
145+
/// The result been returned by command handler.
143146
/// </summary>
147+
/// <remarks>
148+
/// This property can be null even if execution completed with no error.
149+
/// </remarks>
144150
public TView? Response { get; }
145151

146152
/// <summary>
147-
/// 构造一个代表执行失败的 <see cref="CommandResponse{TView,TError}" />
153+
/// Create a <see cref="CommandResponse{TView,TError}" /> with given error.
148154
/// </summary>
149-
/// <param name="errorCode">错误码。</param>
150-
/// <returns></returns>
155+
/// <param name="errorCode">The error.</param>
156+
/// <returns>A <see cref="CommandResponse{TView, TError}"/> with given error.</returns>
151157
public static new CommandResponse<TView, TError> Fail(TError errorCode)
152158
{
153159
return new CommandResponse<TView, TError>(errorCode);
154160
}
155161

156162
/// <summary>
157-
/// 构造一个代表执行成功的 <see cref="CommandResponse{TView,TError}" />
163+
/// Create a <see cref="CommandResponse{TView,TError}" /> with no result nor error.
158164
/// </summary>
159-
/// <returns>代表执行成功的 <see cref="CommandResponse{TView,TError}" />。</returns>
165+
/// <returns>The <see cref="CommandResponse{TView,TError}" />。</returns>
160166
public static new CommandResponse<TView, TError> Success()
161167
{
162168
return new CommandResponse<TView, TError>();
163169
}
164170

165171
/// <summary>
166-
/// 构造一个代表执行成功的 <see cref="CommandResponse{TView,TError}" />
172+
/// Create a <see cref="CommandResponse{TView,TError}" /> with given result.
167173
/// </summary>
168-
/// <param name="view">执行结果。</param>
169-
/// <returns></returns>
174+
/// <param name="view">The model to return.</param>
175+
/// <returns>A <see cref="CommandResponse{TView, TError}"/> with given result.</returns>
170176
public static CommandResponse<TView, TError> Success(TView view)
171177
{
172178
return new CommandResponse<TView, TError>(view);
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
namespace Cnblogs.Architecture.Ddd.Cqrs.Abstractions;
22

33
/// <summary>
4-
/// 定义可缓存的请求
4+
/// Definition for cachable request.
55
/// </summary>
6-
public interface ICacheableRequest
6+
public interface ICachableRequest
77
{
88
/// <summary>
9-
/// 本地缓存配置。
9+
/// Configuration for local cache provider.
1010
/// </summary>
1111
CacheBehavior LocalCacheBehavior { get; set; }
1212

1313
/// <summary>
14-
/// 远程缓存配置。
14+
/// Configuration for remote cache provider.
1515
/// </summary>
1616
CacheBehavior RemoteCacheBehavior { get; set; }
1717

1818
/// <summary>
19-
/// 本地缓存过期时间。
19+
/// The expire time for local cache.
2020
/// </summary>
2121
TimeSpan? LocalExpires { get; set; }
2222

2323
/// <summary>
24-
/// 远程缓存过期时间。
24+
/// The expire time for remote cache.
2525
/// </summary>
2626
TimeSpan? RemoteExpires { get; set; }
2727

2828
/// <summary>
29-
/// 获取缓存分组键,<c>null</c> 代表不分组。
29+
/// Generate key for cache group, return <c>null</c> for no group.
3030
/// </summary>
3131
/// <returns></returns>
3232
string? CacheGroupKey();
3333

3434
/// <summary>
35-
/// 获取缓存键。
35+
/// Generate cache key for each request.
3636
/// </summary>
37-
/// <returns></returns>
37+
/// <returns>The cache key for current request.</returns>
3838
string CacheKey()
3939
{
4040
return string.Join('-', GetCacheKeyParameters().Select(p => p?.ToString()?.ToLower()));
4141
}
4242

4343
/// <summary>
44-
/// 获取组成缓存键的参数。
44+
/// Get parameters for generating cache key, will call <see cref="object.ToString"/> to each object been provided.
4545
/// </summary>
46-
/// <returns></returns>
46+
/// <returns>The parameter array.</returns>
4747
object?[] GetCacheKeyParameters();
4848
}

0 commit comments

Comments
 (0)