cqrs - Command Dispatcher 和 Mediator 设计模式有什么区别?

标签 cqrs mediator

最近我介绍了命令调度程序模式,它可以帮助命令与我们项目中的命令处理程序分离,该模式基于域驱动设计方法和 CQRS 模式。

不管怎样,我把它和 Mediator 设计模式搞混了。

Robert Harvey has already answered关于命令调度程序模式的问题如下:

A Command Dispatcher is an object that links the Action-Request with the appropriate Action-Handler. It's purpose is to decouple the command operation from the sending and receiving objects so that neither has knowledge of the other.



根据维基百科,The mediator pattern被描述为:

With the mediator pattern, communication between objects is encapsulated within a mediator object. Objects no longer communicate directly with each other, but instead communicate through the mediator. This reduces the dependencies between communicating objects, thereby reducing coupling.



因此,据我所知,他们都将命令与指挥官分开,这使我们能够与调用者分离。

我在 Github 上看到了一些项目,它们使用命令调度程序模式来为请求的命令调用所需的处理程序,而其他项目则使用中介者模式来调​​度消息。 (例如,在大多数 DotNet 项目中,MediatR 库用于满足这一点)。

但是,我想知道在我们基于 DDD 方法和 CQRS 模式的项目中使用一种模式与另一种模式有什么区别和好处?

最佳答案

中介者模式在其纯粹的概念中更底层和更通用。中介者模式不定义您使用的通信类型或消息类型。在 Command Dispatcher 中,您处于上层(上下文和概念上),其中已经定义了通信和消息的类型。
您应该能够以 Mediator 模式(ergo with MediatR)为基础实现 Command Dispatcher 模式。

关于cqrs - Command Dispatcher 和 Mediator 设计模式有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57963474/

相关文章:

security - CQRS 应用跨领域问题,例如安全性

java - 中介者模式示例 : chat

oop - 中介者与观察者面向对象设计模式

c# - MVVM:仅将Messenger与自定义对象一起使用以使Send <> “id”唯一吗?

java - 使用中介模式的 Netbeans 平台项目 - 可能吗?

authentication - 是 CQRS 中的登录/注册命令或查询

c# - CQRS,仍然没有完全理解,数据库中保存了什么;(

cqrs - 使用 CQRS 直接从 Axon 聚合的命令处理程序运行查询是否可行?

domain-driven-design - 在 DDD/CQRS 中,ReadModel 是否应该充当 ViewModel,如果不是,那么映射的责任在哪里?

javascript - JS 中的 Observable 模式和 Mediator 模式之间的真正区别是什么?