M
M
Michael2018-05-10 20:29:01
PHP
Michael, 2018-05-10 20:29:01

How to load nested entities in ddd?

I’ll point out right away that ddd doesn’t seem to have any exact implementation instructions. I implement in my own way, based on the needs.
I have entities and repositories for them. In my view, an entity can change its properties and properties of nested entities, as well as load nested entities using their repositories. The problem with such a load is that in the case of creating a list of entities, each of them must load its data, when it would be possible to load the data for all at once with 1 request. This prompted the need for services. It is planned that the service will have a method-command of the loadOrdersForPaymentPage type that will load both entities and nestings in them, and return a ready-made list.
Service example .
Evans quote about services.

When a significant process or transformation in the domain is not a natural responsibility of an ENTITY or VALUE OBJECT, add an operation to the model as standalone interface declared as a SERVICE. Define the interface in terms of the language of the model and make sure the operation name is part of the UBIQUITOUS LANGUAGE. Make the SERVICE stateless .

Are there any downsides to this approach?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
ddd329, 2018-09-19
@ddd329

I have entities and repositories for them.

Repositories are created for entities that are the root of an aggregation.
You cannot load nested entities, because:
1. An entity cannot access the repository, it can only have references to other entities and value objects;
2. It is necessary to load the whole graph at once without any delayed loading.
This is exactly what the units are for.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question