DDD:一对许多用户聚合根和其他聚集体,几乎所有实体之间的关系 [英] DDD: one-to-many relationship between user aggregate root and almost all entities in other aggregates

查看:2306
本文介绍了DDD:一对许多用户聚合根和其他聚集体,几乎所有实体之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下DDD的场景,分为以下几个聚集:
的用户,
朋友(户协会),
档(用户上传),
画廊(组文件),
消息(用户通信),
组(用户可以创建和其他的会员可以加入),发送给一组的所有成员),

GroupMessages(消息GroupForums(组成员可以讨论各种主题)

I have the following DDD scenario, grouped into the following aggregates: User, Friends(User Associations), File(for user uploading), Galleries(grouping of files), Messages(user communication), Groups(users can create and other members can join), GroupMessages(messages sent to all members of a group), GroupForums(group members can discuss various topics)

这是它变得混乱。用户使用都记录下来,以GroupForums有关。似乎没有什么道理要经过用户资源库,虽然访问其他聚集,从层叠的角度来看,如果我删除了用户,在技术上,与用户相关的记录应走为好。看来,如果我不应该添加所有,要么存在这里的用户实体之一一对多关联,作为保湿从数据库中似乎是荒谬的,特别是当我试着拉与用户相关联的每个记录。什么是组织的聚集推荐的策略和存储库以及与很多一到多的关系的处理对于给定的实体的正确方法?

This is where it gets confusing. A user is associated with everything down to GroupForums. It seems illogical to have to go through the User repository to access the other aggregates although, from a cascading standpoint, if I removed the user, technically, the records associated with the user should go away as well. It seems as if I should not add all of the one-to-many associations that exist here to the user entity either, as hydrating from the database seems to be ridiculous, especially if I try pulling every record associated with the user. What is the recommended strategy for organizing your aggregates, and repositories as well as proper way of dealing with alot of one-to-many relationships for a given entity?

任何帮助就因为这个场景似乎很混乱大大appericated。

Any help would be greatly appericated as this scenario seems very confusing.

推荐答案

你使用你的句子'关联'这个词的事实用户与相关的一切......颇为线索。这是绝对的罚款要关联总根源,甚至为一体,以属于'到另一个。但是,你需要看没有AR是否存在的实体。如果可以,它可能有自己的生命周期,应该是一个AR。如果它不能是聚合的一部分。这可能会非常棘手提炼。

The fact that you used the word 'associated' in your sentence "A user is associated with everything..." is quite a clue. It is absolutely fine for aggregate roots to be associated or even for one to 'belong' to another. However, you need to look at whether an entity can exist without the AR. If it can it probably has its own life-cycle and should be an AR. If it can not it is part of the aggregate. This can be tricky to distill.

您需要有在你的人工鱼礁一个非常明确的界限。例如,即使一个论坛可能要求用户创建它,这并不意味着该论坛需要(或者甚至可以)时,用户将被删除被删除。所以在论坛用户可能会,比方说,在 ForumCreator (值对象)只包含用户名和ID。当用户被删除,那么该论坛可以继续它的存在。

You need to have a very clear boundary around your ARs. For example, even though a Forum may require a User to create it this does not mean that the Forum needs to (or even can) be deleted when the user is deleted. So the User in the Forum may become, say, the ForumCreator (a value object) that contains the user name and id only. When the User is deleted then the forum can continue its existence.

在订单/订单行/产品方案,将没有多大意义删除包含的所有订单行具体产品,如果你选择删除它。我知道,一个产品可能应该永远不会被删除,但我们将用它作为一个例子。你只会有相关的产品数据不规范进入订单行,例如:产品ID,产品名称。所以,即使产品名称发生改变,这并不意味着所有的订单行需要更新,甚至应该进行更新。事实上,订单行表示时间和原始的产品名称应保留一个点。买方可能已下令有些lirril产品,然后更名为小产品。不虽然它一样的东西是完全一样的产品。购买者只记得原来的。

In the Order/OrderLine/Product scenario it would not make much sense to delete all order lines that contain a specific product if you choose to delete it. I know that a product probably should never be deleted but we'll use it as an example. You would simply have the relevant product data 'denormalized' into the order line, e.g.: product id, product name. So even if the product name happens to change it does not mean that all order lines need updating, or even should be updated. In fact, the order line represents a point in time and the 'original' product name should be retained. The purchaser may have ordered 'Some lirril product' and then the name changed to 'Little product'. Not the same thing although it is the exact same product. The purchaser only remembers the original.

我希望是有道理的,并以某种方式帮助。你一定要找到那些硬边到你的对象图获取到真正的集合体。

I hope that makes sense and helps in some way. You definitely need to find those hard edges to your object graph to get to the real aggregates.

这篇关于DDD:一对许多用户聚合根和其他聚集体,几乎所有实体之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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