在 DDD 中如何处理 updateAt 这样的实体字段?

发布于 2025-01-16 19:12:44 字数 221 浏览 3 评论 0原文

在 DDD 中,如何处理 updateAt 这样的实体字段? 当实体被修改时,谁负责更新这个字段? 是域层的责任吗?或基础设施层(更新时数据库触发)?或者在应用程序层中,在 $entity->persist() 之前调用 $entity->setupdatedat() ? 如果这是域责任,我们是否必须在域中使用某种事件侦听器/订阅者模式?还有别的事吗?

DDD 最佳实践是什么?

谢谢

In DDD how do you handle entity fields like updatedAt ?
Who is responsible for updating this fields when the entity is modified ?
is it domain layer responsibility ? or infrastructure layer (database trigger on UPDATE) ? or in the application layer, calling $entity->setupdatedat() just before $entity->persist() ?
If it's domain responsibility do we have to use some kind of event listener/subscriber pattern in the domain ? something else ?

What is the DDD best practices ?

Thanks

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

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

发布评论

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

评论(1

喜爱纠缠 2025-01-23 19:12:44

如果它是一个域问题(我们的业务策略关心时钟读数),那么域逻辑通常会获取时钟/时间戳作为其输入之一,然后我们可以在数据模型中存储时间的表示,以便它下次我们加载聚合时可用。

如果是管道问题,那么我们就让管道来处理它。这可能意味着应用程序将元数据复制到数据模型中,或者可能意味着我们的数据模型存储(即:数据库)自动执行此操作。

有时,您可以通过注意需求来自哪里来弄清楚哪个是哪个?如果这是领域专家想要的东西,那么它更有可能是一个领域关注的问题;如果需求来自某些跨领域的关注点(IT、安全),那么它更有可能“只是”元数据。

If it is a domain concern (our business policies care about clock readings), then the domain logic will normally get a clock/timestamp as one of its inputs, and we can then store a representation of the time in the data model so that it is available the next time we load the aggregate.

If it is a plumbing concern, then we let the plumbing handle it. That might mean that the application copies metadata into the data model, or it could mean that our data model storage (ie: the database) does it automatically.

Sometimes, you can figure out which is which by noticing where the requirement is coming from? If this is something that the domain experts want, it is more likely to be a domain concern; if the requirement is coming from some cross-cutting concern (IT, security), then it is more likely to be "just" metadata.

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