gpt4 book ai didi

domain-driven-design - 客户端在 DDD 的存储库模式中是什么意思?

转载 作者:行者123 更新时间:2023-12-04 01:32:45 26 4
gpt4 key购买 nike

我一直在阅读《快速领域驱动设计》一书。
现在我已经达到了存储库模式。

我不确定他们提到“客户”指的是什么?
这里的“客户”是什么意思?

Databases are part of the infrastructure. A poor solution is for the client to be aware of the details needed to access a database. For example, the client has to create SQL queries to retrieve the desired data. The database query may return a set of records, exposing even more of its internal details. When many clients have to create objects directly from the database, it turns out that such code is scattered throughout the entire domain.

最佳答案

存储库的客户端是一段代码(另一个类),通常是 DDD/洋葱架构上下文中的应用层。经验法则是:每个聚合根 1 个存储库。如果您的聚合根是 Order,其中包含 OrderItem 的集合,则您只创建 OrderRepository 并返回带有所有 OrderItem 的整个 Order,没有延迟加载。现在,您的客户端(应用程序层代码)应该不知道存储库内部是什么(它是基于文件的、基于 sql 的还是基于 http 的)您将其视为内存集合:repository.GetById(orderId) 其中存储库是 IOrderRepository。这意味着您可以随时轻松地将存储库从内存中更改为 sql 并返回,并且您的客户端代码(应用程序层)或使用存储库的任何类都不会受到影响,因此保留了 Liskov 替换原则。

关于domain-driven-design - 客户端在 DDD 的存储库模式中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60574779/

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