CQRS / DDD How would I add an object to an aggregate using the command?

I am very new to CQRS / DDD, so there can be big holes in my understanding.

But suppose I have a collection of objects Widget. Widgetconsists of objects Note, and objects Notecan have an object attached to them File.

In CQRS, I can have a command called AddNoteToWidget. From my reading, I know that both command objects and events should be simple DTOs (I know that they can also come in other forms, but the main thing is that they do not contain behavior).

I also understand that entities should never contain references to repositories, as they must be unstable.

Will mine AddNoteToWidgetcontain an object reference Fileand just serialize along with the command? If so, then my object Fileshould be an object of value. However, I modeled it as an object with its own repository, because I wanted to have a central consistent file storage throughout the system.

+4
source share
1 answer

From reading your question, as well as comments on it, it is clear that you are currently referring to Fileboth a sub-entity and an aggregated root . This is a problem, you must solve one of two things:

  • File . File, File. , File .
  • File Widget. , , , Widget. File , Widget WidgetRepository.

. , . .

, , , :

, , .

, , , .

+4

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


All Articles