Is there a common DDD template for working with underload domain objects?

Sometimes when working on applications, especially when trying to follow the appropriate OOD and DDD patterns, we get domain classes such as Customer . Then we have some repository that will load this object, and everything will be fine and clean.

Then the application grows in complexity, and we begin to optimize performance. We often find ourselves in situations where we really do not need to load, say, a list of complete Customer objects, but perhaps just identifiers and names or a small subset of properties (for example, to display in a grid)

Solutions I've often seen include:

  • Non-loaded domain objects, therefore, we will mainly use the Customer class, but we will use a separate repository method to load them, and this repository method will load only the required fields from the database and fill in the corresponding properties in the objects. The remaining Customer fields will remain only by default. This is a simple solution, but can lead to numerous errors if the developer (or existing code) expects to load certain properties.

  • The purpose of the class in which we create classes, such as CustomerIdName , CustomerInfo , CustomerHeader , which contain only the properties we need. Such an approach could create a large number of classes, but with a thorough subclass can be done. It seems to take away from the ubiquitous concept of language language.

So, is there some kind of generally accepted agreement for dealing with people in the DDD world? I tried to do this, but could not find anything authoritative.

Or maybe this is just a known limitation of the classic DDD and CQRS approach, or would other approaches be better in these scenarios?

+5
source share
4 answers

I think the second approach is the way to go. We do this in our projects, but only for reading DTO classes only. As long as you don't use them for insert / update, that's fine, I think.

There is also an answer that may interest you:

+5
source

The well-known limitation of DDD and CQRS is a very good approach to solving it.

The read-side CQRS is basically the No. 2 solution with all the necessary precautions to avoid confusion. Read variable domain models. Entities: no repositories for them, read-only classes, etc.

+2
source

Have you looked at the Entity Framework? They have several levels of lazy object loading: MSDN message

0
source

I don’t understand why there might be a problem while booting. You know which fields are invalid, so they can block access / lazy loading.

0
source

Source: https://habr.com/ru/post/1232993/


All Articles