CQRS 意图命令事件

发布于 2024-10-03 14:49:38 字数 466 浏览 0 评论 0原文

我正在创建一个 Web CRUD 应用程序,在处理内部逻辑后,它将向其他系统发布事件以更新其数据。

我正处于实现 CQRS 的第一步,听起来很奇怪,我必须在一个只有一个“保存”按钮的表单中为用户的所有可能意图创建特定命令。这意味着需要很多命令(针对每个属性或值对象)来捕获我的需求中不需要但在即将订阅它的即将到来的项目中需要的意图。我喜欢只做我的有限上下文需要的事情。

另一件需要考虑的事情是: 我必须使用session来比较数据是否改变。保存后伪造数据将隐藏在 UI 中显示错误数据的并发情况。

编辑:我刚刚发现这个线程其中格雷格Young 表示,有些屏幕只是 CRUD,将更新作为默认行为并没有什么坏处。

I am creating a web CRUD application that, after processing internal logic, will publish events to other systems in order to update their data.

I am in the first step of implementing CQRS and it sounds weird that I have to create specific commands for all possible intentions of the user in a Form where I only have one 'save' button. That means a lot of commands (for each property or value object) to capture an intention not needed in my requirements but needed in the upcoming projects that will subscribe to it. I am a fan of doing ONLY what my bounded context requires.

Another thing to take into account:
I have to use session to compare whether the data has changed or not. Faking the data after saving it will hide concurrency situations showing wrong data in the UI.

EDIT: I just found this thread where Greg Young suggests that some screens are just CRUD and there's nothing bad in making the update as default behavior.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔落墨 2024-10-10 14:49:38

为什么要使用 CQRS?它并不适用于所有情况。

具体来说,如果您使用 CRUD,那么可能根本没有理由尝试 CQRS。它只是不太适合。当用户的意图在 UI 端被显式捕获并以有意义的命令(不是 FieldNameUpdated,而是 CustomerRelocatedToNewAddress 或 CustomerAddressCorrected)传递到服务器时,CQRS 从设计中受益匪浅。这需要在设计中使用领域驱动设计方法)。

Why do you want to use CQRS? It does not work well for all cases.

Specifically, if you are using CRUD, then there might be no reason in trying CQRS at all. It just will not fit well. CQRS benefits a lot from the design, when user's intent is captured explicitly at the UI side and passed down to the server in meaningful command (that's not FieldNameUpdated, but rather CustomerRelocatedToNewAddress or CustomerAddressCorrected). This requires usage of Domain-Driven Design methodologies in the design).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文