c# - 数据访问层和 DDD

标签 c# domain-driven-design

我正在尝试学习领域驱动设计的思想,并试图弄清楚我们应该将数据库持久性代码放在哪里。

阅读 Vaughn Vernon 的“实现域驱动设计”一书,我了解到存储库或数据库操作(连同连接等)必须保存在模型项目(域模型上下文)本身中。我的理解正确吗?

我指的是他的 IdentityAccessContext、AgilePMContext 等示例,其中有存储库的接口(interface)。我一直有一个想法,那就是拥有一个单独的数据层,在这里添加一个数据层会导致循环依赖。因为接口(interface)、实体是在数据层所需的模型中声明的,并且数据层需要从模型中引用以实现持久性。

这是正确的还是我遗漏了什么?

最佳答案

Going through the book "Implementing Domain Driven Design by Vaughn Vernon", I understand that the Repository or the Database operations (along with connections etc.,) have to be kept in the Model project (Domain Model Context) itself. Is my understanding correct?

存储库抽象(接口(interface))应该在领域层,但它们的具体实现在基础设施层。

请参阅他的本书代码示例:https://github.com/VaughnVernon/IDDD_Samples/tree/master/iddd_agilepm/src/main/java/com/saasovation/agilepm ,例如域/模型中的 TeamRepository 接口(interface)和端口/适配器/持久性中的 LevelDBTeamMemberRepository

没有循环引用,因为持久性与域强耦合,但域仅在需要时才与持久性松散耦合(多亏了控制反转,大部分时间通过依赖注入(inject)实现)。

关于c# - 数据访问层和 DDD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32123973/

相关文章:

domain-driven-design - 事件源系统中的预测

c# - 我的程序无故从一行跳到另一行 (C#)

c# - 在 Windows 窗体应用程序中隐藏 xml 文件

c# - 使用随机时如何始终选择不同的随机短语?

c# - 需要领域建模建议 - 希望是常见场景

domain-driven-design - 创建概念领域模型的方法

mysql - 如何使用流畅的 api 在 EF6 中映射值对象标识?

c# - Npgsql 我得到 : 42P01: relation "sometable" does not exist

c# - VLC:将文件移动到末尾

repository - DDD : Do item counts belong in domain model?