CQRS是否对我的域正确? [英] Is CQRS correct for my domain?

查看:59
本文介绍了CQRS是否对我的域正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建模一个存档,该存档是视频需求系统的一部分。可以将档案想像成Windows资源管理器,其中多个用户可以创建文件夹,上传视频,重组文件夹等。有业务规则(权限)确定用户是否被允许执行任务(即重命名文件夹,移动文件夹,查看文件夹等) )。

I am modelling an archive which is part of an video demand system. Think of the archive like windows explorer where multiple users can create folders, upload videos, restructure folders etc. There are business rules (permissions) which determine if the user is allowed to do the task (i.e. rename folder, move folders, view folders etc).

我已将每个文件夹建模为一个聚合根,将一个文件夹移动到另一个文件夹似乎会影响两个聚合根。

I have modeled each folder as an aggregate root and moving one folder to another folder appears to affect two aggregate roots.

据我了解,我应该发送一个事件来修改其他聚合。但是,令我担心的是,如果第二个文件夹也已被修改(例如从系统中删除或删除),那么我需要发送补偿命令来撤消第一个汇总更改。

From what I understand is I should send an event to modify the other aggregate. However what concerns me is if the second folder has also been modified (say deleted or removed from the system) then I need to send a compensating command to undo the first aggregate change.

我希望使用某种类型的交易来处理移动(两个总量的变化),如果失败,那么至少我不需要撤消第一部分

I would prefer some sort of transaction that deals with the move (change on both aggregates) together and if it fails then at least I do not need to undo the first part of the move or raise the first part of the event.

这使我想到,CQRS是否适合我要解决的问题?

This leads me to, is CQRS right for the problem I am trying to solve? And if so could it be that my aggregates are wrong?

推荐答案

在DDD中,聚合应该代表事务边界。一项交易需要涉及多个汇总,这通常表明该模型应该完善,或者交易需求应进行审查,或者两者同时进行。

In DDD the Aggregate should represent the transactional boundary. A transaction that requires the involvement of more than one aggregate is often a sign that either the model should be refined, or the transactional requirements should be reviewed, or both.

一个纯粹的DDD问题,并且独立于CQRS或任何其他体系结构模式。

This a pure DDD issue and is independent of CQRS or any other architectural pattern.

另一方面,您是否真的需要重塑分层结构,例如包含文件的文件夹?据我所知,这已经解决了很长时间了。

On the other hand, do you really need to reinvent hierarchical structures like folders containing files? As far as I can tell this has been a solved problem for quite some time. Maybe there's no inherent advantage in formalizing that specific domain once again.

使用DDD模式进行域建模在有限的上下文中最有意义,其中(1)域非常复杂(2)对域进行建模将使您的软件比同类应用程序具有真正的(例如,竞争性)优势。如果该特定的有界上下文非常简单和/或没有带来很大的优势,那么最好使用最简单的解决方案。

Domain modeling using the patterns of DDD makes most sense in bounded contexts where (1) the domain is very complex and (2) modeling the domain will give your software a real (e.g. competitive) advantage over similar applications. If that specific bounded context is rather simple and/or remodeling it doesn't bring a really great advantage, you are better off using the simplest possible solution.

恕我直言,域驱动设计中最重要的概念是关注核心域

This represents the IMHO most important concept in Domain-Driven Design, which is Focus on the Core Domain

这篇关于CQRS是否对我的域正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆