Reputation: 22171
According to many programers, DAO layer can be bypassed when using JPA.
While using DDD approach, domain layer composes of infrastructure region (containing external resources like repositories implementations) and domain region (with entities, needed value objects and repositories interfaces and services etc...).
Thus, if DOA layer is skipped, should the infrastructure region be part of domain layer within a package called 'infrastructure' for instance ?
If infrastructure part should be moved in a separated layer (separated project to get things cleaner), are circular dependencies acceptable between domain layer and infrastrure layer? Indeed, entities and interface repositories must be shared.
Otherwise, should I separate entities and repositories interfaces from Domain layer in order to be considered as an independent thing shared by domain and infrastructure ?
What is the good practice ?
Upvotes: 1
Views: 1935
Reputation: 14064
In DDD, the data access objects (DAOs) are Repositories. There's no "DAO layer", persistence is part of the Infrastructure layer.
As you mentioned, the contracts (interfaces) of Repositories are defined in the Domain layer while their concrete implementation resides in the Infrastructure layer.
There's no need for the Domain layer to reference the Infrastructure since entities are supposed to be pure domain objects, unaware of how they are persisted, transferred to other systems, and so on.
"In other words, each of the layers uses an abstract interface that represents it's infrastructure needs. It does not know what infrastructure it will be using. It simply states it's needs through an abstract interface and expects the infrastructure to implement that interface and supply the required functionality."
http://www.artima.com/weblogs/viewpost.jsp?thread=35139
Upvotes: 2
Reputation: 3634
A DAO layer and a infrastructure region/domain region are not the same things. DAO layers are used when implementing the infrastructure/domain regions.
Your programmers are correct, JPA is the DAO layer. You still need the infrastructure region and domain regions. They'll just be smaller/differnet then if you had to implement a DAO layer within these two regions.
Upvotes: 1