From d85b5b6539551c50ebd591d2e67cbc2017cc5e87 Mon Sep 17 00:00:00 2001 From: hello Date: Fri, 30 Aug 2024 15:05:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=AE=A2=E5=8D=95=E5=BE=AE?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- notes/helloshop/ordering-entities.md | 0 notes/helloshop/ordering-service.md | 15 ++++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 notes/helloshop/ordering-entities.md diff --git a/notes/helloshop/ordering-entities.md b/notes/helloshop/ordering-entities.md new file mode 100644 index 0000000..e69de29 diff --git a/notes/helloshop/ordering-service.md b/notes/helloshop/ordering-service.md index 2745f66..782cb7f 100644 --- a/notes/helloshop/ordering-service.md +++ b/notes/helloshop/ordering-service.md @@ -5,19 +5,17 @@ CQRS 是命令和查询责任分离的英文缩写,它是一种将读取操作 ## 为什么要使用 CQRS 模式 -在传统的体系结构中,使用同一数据模型查询和更新数据库。 这十分简单,非常适用于基本的 CRUD 操作。 -![crud](https://oss.xcode.me/notes/helloshop/crud.png) +在传统的体系结构中,使用同一数据模型查询和更新数据库。 这十分简单,非常适用于基本的 CRUD 操作。 CQRS 将读取和写入分离到不同的模型,使用命令来更新数据,使用查询来读取数据。读取存储可以是写入存储的只读副本,或者读取和写入存储可以具有完全不同的结构。 使用多个只读副本可以提高查询性能,尤其是在只读副本靠近应用程序实例的分布式方案中。 -![cqrs](https://oss.xcode.me/notes/helloshop/cqrs.png) - - ## 使用 MediatR 实现 CQRS 中的 Command 模式 +![ordering-service-flow](https://oss.xcode.me/notes/helloshop/ordering-service-flow.svg) + ```shell dotnet add package MediatR ``` @@ -72,6 +70,8 @@ builder.Services.AddMediatR(options => options.RegisterServicesFromAssembly(Asse ## 使用 Mediator 请求管道处理 CQRS 中的命令 +![ordering-service-identified-command](https://oss.xcode.me/notes/helloshop/ordering-service-identified-command.svg) + `LoggingBehavior`、`ValidatorBehavior` 和 `TransactionBehavior` ```csharp @@ -129,6 +129,11 @@ services.AddDaprClient(); builder.Services.AddTransient>(); ``` +## 通用类型映射和验证 + +![ordering-service-validator-mapper](https://oss.xcode.me/notes/helloshop/ordering-service-validator-mapper.svg) + + ## 参考资料