实现订单微服务
This commit is contained in:
parent
3101ff4e97
commit
d85b5b6539
0
notes/helloshop/ordering-entities.md
Normal file
0
notes/helloshop/ordering-entities.md
Normal file
@ -5,19 +5,17 @@ CQRS 是命令和查询责任分离的英文缩写,它是一种将读取操作
|
|||||||
|
|
||||||
## 为什么要使用 CQRS 模式
|
## 为什么要使用 CQRS 模式
|
||||||
|
|
||||||
在传统的体系结构中,使用同一数据模型查询和更新数据库。 这十分简单,非常适用于基本的 CRUD 操作。
|
|
||||||
|
|
||||||

|
在传统的体系结构中,使用同一数据模型查询和更新数据库。 这十分简单,非常适用于基本的 CRUD 操作。
|
||||||
|
|
||||||
|
|
||||||
CQRS 将读取和写入分离到不同的模型,使用命令来更新数据,使用查询来读取数据。读取存储可以是写入存储的只读副本,或者读取和写入存储可以具有完全不同的结构。 使用多个只读副本可以提高查询性能,尤其是在只读副本靠近应用程序实例的分布式方案中。
|
CQRS 将读取和写入分离到不同的模型,使用命令来更新数据,使用查询来读取数据。读取存储可以是写入存储的只读副本,或者读取和写入存储可以具有完全不同的结构。 使用多个只读副本可以提高查询性能,尤其是在只读副本靠近应用程序实例的分布式方案中。
|
||||||
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
## 使用 MediatR 实现 CQRS 中的 Command 模式
|
## 使用 MediatR 实现 CQRS 中的 Command 模式
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
dotnet add package MediatR
|
dotnet add package MediatR
|
||||||
```
|
```
|
||||||
@ -72,6 +70,8 @@ builder.Services.AddMediatR(options => options.RegisterServicesFromAssembly(Asse
|
|||||||
|
|
||||||
## 使用 Mediator 请求管道处理 CQRS 中的命令
|
## 使用 Mediator 请求管道处理 CQRS 中的命令
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
`LoggingBehavior`、`ValidatorBehavior` 和 `TransactionBehavior`
|
`LoggingBehavior`、`ValidatorBehavior` 和 `TransactionBehavior`
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
@ -129,6 +129,11 @@ services.AddDaprClient();
|
|||||||
builder.Services.AddTransient<IDistributedEventLogService, DistributedEventLogService<OrderingServiceDbContext>>();
|
builder.Services.AddTransient<IDistributedEventLogService, DistributedEventLogService<OrderingServiceDbContext>>();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 通用类型映射和验证
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 参考资料
|
## 参考资料
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user