We have an issue with how the implementation of the Data Access layer (EF6 Includes more specifically), influences the behavior of our Domain layer.
A theoretical example to illustrate:
Application in 3 layers, DDD:
Domain layer: simplistic domain model
Orderhas a public property
"CanBeExtended". Business logic is
Data Access layer: this layer contains the
OrderRepository, which uses EF6 to retrieve an
Order object from the database.
GetOrderByIdis the only relevant method for this example
Service layer: contains "Controllers" in MVC-speak, is accessed via the API
"CanOrderBeExtended": input is the id of the order, returns a bool whether the order can be extended
Implementation of this Service layer:
Order object from the repository using
GetOrderById, then call its property
CanBeExtended, and return that value.
Depending on the implementation of the Data Access layer, the Domain layer behaves wrong: depending on whether you
Orderlines of the
CanBeExtended behaves differently.
When you forget the
Orders are extendable.
We're looking for a more fundamental solution:
How can we mitigate this dependency between the Domain and the Data Access layer?
How can we make sure we don't forget
This example might then use something like
"GetOrderWithOrderLinesById" which contains the
Include(o => o.OrderLines).
But to decide which method is needed, we'd have to review the implementation of
CanBeExtended in the Domain layer.
Additionally, when that implementation changes, the repository method needs to change as well (e.g. to add extra
Include statements), or another, new method would turn out to be needed, thus highly coupling the Repository (in the Data Access layer) with the Domain layer.
Fowler nor Evans seem to touch this specific topic AFAIK.
Any and all thoughts welcome!