gpt4 book ai didi

domain-driven-design - DDD 和实现持久化

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

我第一次接触到 DDD(在 .Net 中),因为我正在重新构建遗留企业应用程序的一些核心组件。

我想澄清的是,我们如何在适当的 DDD 架构中实现持久性?

我意识到域本身是无知的持久性,应该使用“无处不在的语言”进行设计,当然不会被迫受到当月的 DAC 甚至物理数据库的约束。

我是否正确存储库接口(interface)存在于域程序集中,但存储库实现存在于持久层中?持久层包含对域层的引用,反之亦然?

从哪里调用我的实际存储库方法 (CRUD)?

最佳答案

Am I correct that the Repository Interfaces live within the Domain assembly, but the Repository Implementations exist within the persistence layer? The persistence layer contains a reference to the Domain layer, never vice versa?



是的,这是一个非常好的方法。

Where are my actual repository methods (CRUD) being called from?



最好不要以 CRUD 术语思考,因为它过于以数据为中心,可能会导致您进入 Generic Repository Trap。 . Repository帮助管理 domain objects 的中间和生命末期. Factories往往负责开始。请记住,当对象从数据库中恢复时,从 DDD 的角度来看,它处于其中期阶段。这就是代码的样子:
// beginning 
Customer preferredCustomer = CustomerFactory.CreatePreferred();
customersRepository.Add(preferredCustomer);

// middle life
IList<Customer> valuedCustomers = customersRepository.FindPrefered();

// end life
customersRepository.Archive(customer);

您可以直接从您的应用程序调用此代码。也许值得下载并查看 Evan 的 DDD Sample . Unit of Work模式通常用于处理事务和抽象您选择的 ORM。

关于domain-driven-design - DDD 和实现持久化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7164034/

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