Pergunta

During my short experience with DDD I often find myself in the situation where I wished for some type of lazy loading mechanism to solve some dangerous cases where large nested data sets might be loaded.

However after a while I realized that each time, that was the symptom of a poorly designed aggregate root that was taking too much responsibility. Additionally it used to be the case where the aggregates should be fully loaded to perform consistency operations. Getting used to work with Entity ids made things slightly easier.

So after a while, I am wondering... is lazy loading a code smell? Is it something just to build non mature models without causing a big problem?

Foi útil?

Solução

My short answer: yes!

Lazy loading and other fetching strategies indicate that the domain model is being used to perform queries. This is something that should not be done. A simple query layer best serves that purpose. So, in my opinion, you have come to the correct conclusion :)

The domain model should only contain current transactional state. This means that, typically, there should be no large data sets as these are more common for historical data. This does not mean that historical data cannot be used to create new transaction aggregates, though.

Licenciado em: CC-BY-SA com atribuição
scroll top