gpt4 book ai didi

domain-driven-design - 域模型可以知道存储库吗?

转载 作者:行者123 更新时间:2023-12-04 18:12:02 24 4
gpt4 key购买 nike

可能是某些域逻辑实现实体需要访问 repo 以更新/删除自身或任何相关实体。这听起来对吗??

最佳答案

不,它没有,至少对于带有“领域驱动设计”标签的问题。
当然,Active Record 模式有权存在于某些系统中,并且有些人发现强耦合很有用,但在 DDD 中建议的方式是显式使用存储库:

Evans DDD, p.152: For each type of object that needs global access, create an object that can provide the illusion of an in-memory collection of all objects of that type. «...» Provide REPOSITORIES only for AGGREGATE roots that actually need direct access. Keep the client focused on the model, delegating all object storage and access to the REPOSITORIES.



因此,在 DDD 中,存储库不仅封装了访问数据库所需的基础架构代码,还封装了必须存储和加载对象的整个想法。

如果您正在执行一些涉及从数据库保存和加载的复合操作,那么具有对存储库的引用的服务是最佳候选者。

关于domain-driven-design - 域模型可以知道存储库吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11818160/

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