在应用程序,域和基础架构层(DDD)中的存储库实现

发布于 2025-01-23 20:00:04 字数 326 浏览 0 评论 0 原文

我有这样的项目结构:

​层。同样,对于称为“ iRepository”的通用存储库,

我对在哪里实施特定存储库有疑问?在这种情况下,我有 iProDuctRepository Application 层中定义的。那么,我应该在哪里实施?在应用程序层本身?还是在基础结构层

请指导。

I have a project structure like this :

enter image description here

Here, IApplicationDbContext.cs interface defined in Application layer and it's implementation is done in Infrastructure layer. Similarly for Generic Repository called `IRepository'

I have a doubt about where to implement the Specific Repositories? in this case, I have IProductRepository defined in the Application Layer. So, where should I implement this? In the Application Layer itself? or in the Infrastructure Layer?

Please guide.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流云如水 2025-01-30 20:00:04

存储库实施

应用程序的基础结构层表示能够功能的技术细节。它负责在域对象状态的技术实施中进行技术实施。

因此,存储库实现属于基础结构层,因为它们处理存储,这不是一个责任
该模型应进行。通常,它可以由持久框架来支持繁重的举动。必须在基础结构层下实现特定的存储库。

存储库合同

根据DDD 存储库合同应在所有域对象旁边的域层中定义。高级模块不应取决于低级模块。两者都应取决于抽象。抽象不应取决于细节。细节应取决于抽象。基于此规则,我们无法在基础结构层中定义存储库接口。存储库也可以由域层使用,在这种情况下,我们无法在应用程序层中定义合同。
存储库是域模型与持久性之间的合同。它应仅根据领域而没有思考潜在的持久性书写。存储库的合同不仅仅是CRUD接口。它是域模型的扩展,并用域专家理解的术语编写。您的存储库应是根据应用程序用例的需求而不是从类似CRUD的数据访问的角度来构建的。

对于分层体系结构中的存储库?

nofollow noreferrer“> domain-driven-driven-drive-driven-driven-driven-densign-design insimention-guide-guide-guide guide <<< /a>

存储库客户端

存储库的典型客户端是应用程序服务层

域服务也可以使用存储库。


参考文献:

vaughn vernon-实现域驱动的设计

“ nofollow noreferrer”>模式,原理和实践,域驱动的设计第一版
由Scott Millett

Repository implementation

The Infrastructural Layer of an application represents the technical details that enable it to function. It is responsible for the technical implementation of storing information on the state of domain objects.

So the Repository implementation comes under the Infrastructure Layer because they deal with storage, which is not a responsibility
that the model should take on. It is usually backed by a persistence framework to do the heavy lifting. Specific Repositories must be implemented under the Infrastructure Layer.

Repository contract

According to DDD Repository contract should be defined in the Domain Layer next to all of the domain objects. High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend upon details. Details should depend upon abstractions. Based on this rule we can't define repository interface in Infrastructure layer. Repository also can be used by Domain Layer in this case we can not define contract in Application Layer.
The repository is the contract between the domain model and the persistence. It should be written only in terms of the Domain and without a thought to the underlying persistence. The contract of a repository is more than just a CRUD interface. It is an extension of the domain model and is written in terms that the domain expert understands. Your repository should be built from the needs of the application use cases rather than from a CRUD‐like data access standpoint.

Where to define the interfaces for a repository in an layered architecture?

Domain-Driven-Design Implementation-Guide

Repository client

A typical client of a Repository is the Application Service Layer.

Domain Services also can use repositories.

enter image description here
enter image description here

References:

Vaughn Vernon - Implementing Domain-Driven Design

Patterns, Principles, and Practices of Domain-Driven Design 1st Edition
by Scott Millett

还在原地等你 2025-01-30 20:00:04

iProductrepository - 域层。 “产品存储库”是一个明确表示域实体存储的业务概念。它可以很好地转化为现实世界。

IProductRepository - Domain Layer. "Product Repository" is a business concept that explicitly represents the storage of a domain entity. It translates well to the real world.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文