我有这样的项目结构:
层。同样,对于称为“ iRepository”的通用存储库,
我对在哪里实施特定存储库有疑问?在这种情况下,我有 iProDuctRepository
在 Application
层中定义的。那么,我应该在哪里实施?在应用程序层
本身?还是在基础结构层
?
请指导。
I have a project structure like this :
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.
发布评论
评论(2)
存储库实施
应用程序的
基础结构层
表示能够功能的技术细节。它负责在域对象状态的技术实施中进行技术实施。因此,
存储库实现
属于基础结构层
,因为它们处理存储,这不是一个责任该模型应进行。通常,它可以由持久框架来支持繁重的举动。必须在
基础结构层
下实现特定的存储库。存储库合同
根据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 theInfrastructure Layer
because they deal with storage, which is not a responsibilitythat 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 theDomain 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 inInfrastructure layer
. Repository also can be used byDomain Layer
in this case we can not define contract inApplication 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 theApplication Service Layer
.Domain Services
also can use repositories.References:
Vaughn Vernon - Implementing Domain-Driven Design
Patterns, Principles, and Practices of Domain-Driven Design 1st Edition
by Scott Millett
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.