gpt4 book ai didi

entity - DDD : Should Repository validate Entity before persisting it?

转载 作者:行者123 更新时间:2023-12-01 09:25:03 24 4
gpt4 key购买 nike

简单的问题:存储库应该在持久化之前验证实体吗? Validate = 检查所有值是否符合规则(例如 Name is < 50 chars 等)。

最佳答案

在 DDD 中,每个聚合都应对其有效性负责。永远不应该有一个对象处于无效状态。即每个聚合都应该拒绝任何会导致无效状态的突变。

引自一篇关于该主题的精彩文章,Validation in a DDD World , 吉姆·博加德:

Simply put, if we control the operation side of the equation, why in the world would we allow our entities to get into an invalid state? Life becomes much more complicated if we start having “IsValid” properties on our entities.

关于entity - DDD : Should Repository validate Entity before persisting it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26412871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com