99namespace Cnblogs . Architecture . Ddd . Cqrs . AspNetCore ;
1010
1111/// <summary>
12- /// 用于 Minimum API CQRS 路径注册的扩展方法。
12+ /// Extension methods used for register Command and Query endpoint in minimal API.
1313/// </summary>
1414public static class CqrsRouteMapper
1515{
@@ -18,11 +18,11 @@ public static class CqrsRouteMapper
1818 private static readonly List < Type > CommandTypes = new ( ) { typeof ( ICommand < > ) , typeof ( ICommand < , > ) } ;
1919
2020 /// <summary>
21- /// 添加查询 API,使用 GET 方法访问,参数将自动从路径或查询字符串获取。
21+ /// Map a query API, using GET method. <typeparamref name="T"/> would been constructed from route and query string.
2222 /// </summary>
2323 /// <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>
2626 /// <returns></returns>
2727 public static IEndpointConventionBuilder MapQuery < T > (
2828 this IEndpointRouteBuilder app ,
@@ -32,11 +32,11 @@ public static IEndpointConventionBuilder MapQuery<T>(
3232 }
3333
3434 /// <summary>
35- /// 添加一个命令 API,根据前缀选择 HTTP Method,错误会被自动处理。
35+ /// Map a command API, using different HTTP methods based on prefix. See example for details.
3636 /// </summary>
3737 /// <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>
4040 /// <example>
4141 /// <code>
4242 /// app.MapCommand<CreateItemCommand>("/items"); // Starts with 'Create' or 'Add' - POST
@@ -54,36 +54,11 @@ public static IEndpointConventionBuilder MapCommand<T>(
5454 }
5555
5656 /// <summary>
57- /// 添加一个命令 API,根据前缀选择 HTTP Method,错误会被自动处理。
57+ /// Map a query API, using GET method.
5858 /// </summary>
5959 /// <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>
8762 /// <returns></returns>
8863 public static IEndpointConventionBuilder MapQuery (
8964 this IEndpointRouteBuilder app ,
@@ -102,11 +77,11 @@ public static IEndpointConventionBuilder MapQuery(
10277 }
10378
10479 /// <summary>
105- /// 添加一个命令 API,根据前缀选择 HTTP Method,错误会被自动处理。
80+ /// Map a command API, using different method based on type name prefix.
10681 /// </summary>
10782 /// <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>
11085 /// <returns></returns>
11186 /// <example>
11287 /// <code>
@@ -142,11 +117,11 @@ public static IEndpointConventionBuilder MapCommand(
142117 }
143118
144119 /// <summary>
145- /// 添加一个命令 API,使用 POST 方法访问,错误会被自动处理。
120+ /// Map a command API, using POST method.
146121 /// </summary>
147122 /// <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>
150125 /// <returns></returns>
151126 public static IEndpointConventionBuilder MapPostCommand (
152127 this IEndpointRouteBuilder app ,
@@ -158,11 +133,11 @@ public static IEndpointConventionBuilder MapPostCommand(
158133 }
159134
160135 /// <summary>
161- /// 添加一个命令 API,使用 PUT 方法访问,错误会被自动处理。
136+ /// Map a command API, using PUT method.
162137 /// </summary>
163138 /// <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>
166141 /// <returns></returns>
167142 public static IEndpointConventionBuilder MapPutCommand (
168143 this IEndpointRouteBuilder app ,
@@ -174,11 +149,11 @@ public static IEndpointConventionBuilder MapPutCommand(
174149 }
175150
176151 /// <summary>
177- /// 添加一个命令 API,使用 DELETE 方法访问,错误会被自动处理。
152+ /// Map a command API, using DELETE method.
178153 /// </summary>
179154 /// <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>
182157 /// <returns></returns>
183158 public static IEndpointConventionBuilder MapDeleteCommand (
184159 this IEndpointRouteBuilder app ,
@@ -199,4 +174,4 @@ private static void EnsureDelegateReturnTypeIsCommand(Delegate handler)
199174 "handler does not return command, check if delegate returns type that implements ICommand<> or ICommand<,>" ) ;
200175 }
201176 }
202- }
177+ }
0 commit comments