9
9
namespace Cnblogs . Architecture . Ddd . Cqrs . AspNetCore ;
10
10
11
11
/// <summary>
12
- /// 用于 Minimum API CQRS 路径注册的扩展方法。
12
+ /// Extension methods used for register Command and Query endpoint in minimal API.
13
13
/// </summary>
14
14
public static class CqrsRouteMapper
15
15
{
@@ -18,11 +18,11 @@ public static class CqrsRouteMapper
18
18
private static readonly List < Type > CommandTypes = new ( ) { typeof ( ICommand < > ) , typeof ( ICommand < , > ) } ;
19
19
20
20
/// <summary>
21
- /// 添加查询 API,使用 GET 方法访问,参数将自动从路径或查询字符串获取。
21
+ /// Map a query API, using GET method. <typeparamref name="T"/> would been constructed from route and query string.
22
22
/// </summary>
23
23
/// <param name="app"><see cref="IApplicationBuilder"/></param>
24
- /// <param name="route">路径模板。 </param>
25
- /// <typeparam name="T">查询类型。 </typeparam>
24
+ /// <param name="route">The route template for API. </param>
25
+ /// <typeparam name="T">The type of the query. </typeparam>
26
26
/// <returns></returns>
27
27
public static IEndpointConventionBuilder MapQuery < T > (
28
28
this IEndpointRouteBuilder app ,
@@ -32,11 +32,11 @@ public static IEndpointConventionBuilder MapQuery<T>(
32
32
}
33
33
34
34
/// <summary>
35
- /// 添加一个命令 API,根据前缀选择 HTTP Method,错误会被自动处理。
35
+ /// Map a command API, using different HTTP methods based on prefix. See example for details.
36
36
/// </summary>
37
37
/// <param name="app"><see cref="ApplicationBuilder"/></param>
38
- /// <param name="route">路径模板。 </param>
39
- /// <typeparam name="T">命令类型。 </typeparam>
38
+ /// <param name="route">The route template. </param>
39
+ /// <typeparam name="T">The type of the command. </typeparam>
40
40
/// <example>
41
41
/// <code>
42
42
/// app.MapCommand<CreateItemCommand>("/items"); // Starts with 'Create' or 'Add' - POST
@@ -54,36 +54,11 @@ public static IEndpointConventionBuilder MapCommand<T>(
54
54
}
55
55
56
56
/// <summary>
57
- /// 添加一个命令 API,根据前缀选择 HTTP Method,错误会被自动处理。
57
+ /// Map a query API, using GET method.
58
58
/// </summary>
59
59
/// <param name="app"><see cref="ApplicationBuilder"/></param>
60
- /// <param name="route">路径模板。</param>
61
- /// <param name="handler">返回 <typeparamref name="T"/> 的委托。</param>
62
- /// <typeparam name="T">命令类型。</typeparam>
63
- /// <example>
64
- /// <code>
65
- /// app.MapCommand<CreateItemCommand>("/items"); // Starts with 'Create' or 'Add' - POST
66
- /// app.MapCommand<UpdateItemCommand>("/items/{id:int}") // Starts with 'Update' or 'Replace' - PUT
67
- /// app.MapCommand<DeleteCommand>("/items/{id:int}") // Starts with 'Delete' or 'Remove' - DELETE
68
- /// app.MapCommand<ResetItemCommand>("/items/{id:int}:reset) // Others - PUT
69
- /// </code>
70
- /// </example>
71
- /// <returns></returns>
72
- // ReSharper disable once UnusedTypeParameter
73
- public static IEndpointConventionBuilder MapCommand < T > (
74
- this IEndpointRouteBuilder app ,
75
- [ StringSyntax ( "Route" ) ] string route ,
76
- Delegate handler )
77
- {
78
- return app . MapCommand ( route , handler ) ;
79
- }
80
-
81
- /// <summary>
82
- /// 添加一个查询 API,使用 GET 方法访问。
83
- /// </summary>
84
- /// <param name="app"><see cref="ApplicationBuilder"/></param>
85
- /// <param name="route">路径模板。</param>
86
- /// <param name="handler">构造查询的方法,需要返回 <see cref="IQuery{TView}"/> 的对象。</param>
60
+ /// <param name="route">The route template.</param>
61
+ /// <param name="handler">The delegate that returns a <see cref="IQuery{TView}"/> instance.</param>
87
62
/// <returns></returns>
88
63
public static IEndpointConventionBuilder MapQuery (
89
64
this IEndpointRouteBuilder app ,
@@ -102,11 +77,11 @@ public static IEndpointConventionBuilder MapQuery(
102
77
}
103
78
104
79
/// <summary>
105
- /// 添加一个命令 API,根据前缀选择 HTTP Method,错误会被自动处理。
80
+ /// Map a command API, using different method based on type name prefix.
106
81
/// </summary>
107
82
/// <param name="app"><see cref="ApplicationBuilder"/></param>
108
- /// <param name="route">路径模板。 </param>
109
- /// <param name="handler">构造命令的方法,需要返回 <see cref="ICommand{TError}"/> 类型的对象。 </param>
83
+ /// <param name="route">The route template. </param>
84
+ /// <param name="handler">The delegate that returns a instance of <see cref="ICommand{TError}"/>. </param>
110
85
/// <returns></returns>
111
86
/// <example>
112
87
/// <code>
@@ -142,11 +117,11 @@ public static IEndpointConventionBuilder MapCommand(
142
117
}
143
118
144
119
/// <summary>
145
- /// 添加一个命令 API,使用 POST 方法访问,错误会被自动处理。
120
+ /// Map a command API, using POST method.
146
121
/// </summary>
147
122
/// <param name="app"><see cref="ApplicationBuilder"/></param>
148
- /// <param name="route">路径模板。 </param>
149
- /// <param name="handler">构造命令的方法,需要返回 <see cref="ICommand{TError}"/> 类型的对象。 </param>
123
+ /// <param name="route">The route template. </param>
124
+ /// <param name="handler">The delegate that returns a instance of <see cref="ICommand{TError}"/>. </param>
150
125
/// <returns></returns>
151
126
public static IEndpointConventionBuilder MapPostCommand (
152
127
this IEndpointRouteBuilder app ,
@@ -158,11 +133,11 @@ public static IEndpointConventionBuilder MapPostCommand(
158
133
}
159
134
160
135
/// <summary>
161
- /// 添加一个命令 API,使用 PUT 方法访问,错误会被自动处理。
136
+ /// Map a command API, using PUT method.
162
137
/// </summary>
163
138
/// <param name="app"><see cref="ApplicationBuilder"/></param>
164
- /// <param name="route">路径模板。 </param>
165
- /// <param name="handler">构造命令的方法,需要返回 <see cref="ICommand{TError}"/> 类型的对象。 </param>
139
+ /// <param name="route">The route template. </param>
140
+ /// <param name="handler">The delegate that returns a instance of <see cref="ICommand{TError}"/>. </param>
166
141
/// <returns></returns>
167
142
public static IEndpointConventionBuilder MapPutCommand (
168
143
this IEndpointRouteBuilder app ,
@@ -174,11 +149,11 @@ public static IEndpointConventionBuilder MapPutCommand(
174
149
}
175
150
176
151
/// <summary>
177
- /// 添加一个命令 API,使用 DELETE 方法访问,错误会被自动处理。
152
+ /// Map a command API, using DELETE method.
178
153
/// </summary>
179
154
/// <param name="app"><see cref="ApplicationBuilder"/></param>
180
- /// <param name="route">路径模板。 </param>
181
- /// <param name="handler">构造命令的方法,需要返回 <see cref="ICommand{TError}"/> 类型的对象。 </param>
155
+ /// <param name="route">The route template. </param>
156
+ /// <param name="handler">The delegate that returns a instance of <see cref="ICommand{TError}"/>. </param>
182
157
/// <returns></returns>
183
158
public static IEndpointConventionBuilder MapDeleteCommand (
184
159
this IEndpointRouteBuilder app ,
@@ -199,4 +174,4 @@ private static void EnsureDelegateReturnTypeIsCommand(Delegate handler)
199
174
"handler does not return command, check if delegate returns type that implements ICommand<> or ICommand<,>" ) ;
200
175
}
201
176
}
202
- }
177
+ }
0 commit comments