In the articles/books on ddd in the chapters that treat aggregates I have the feeling that a subject is never discussed :
How to reload an aggregate ?
- Either it's too obvious and it's useless to talk about it
- Either it's not the right thing to do
- Either I don't understand
If I take the example of the order with these items create or update my invariants are the same. Let's say that I have to update a price on an item of an already existing order, so I will start by reloading my aggregates.
But how do I do this ?
Use a tool such as automapper which will be able to set the private property ?
Use a constructor that takes the id of the root aggregate, the child repositories and assign the private property in this constructor ?
Rebuild everything from scratch item by item as if I was creating a new one ?
Usually this one.
Load the data from the persistent store using whatever the appropriate general purpose mechanism is: an array of bytes, a json document, record sets, whatever. Now that you have the information in memory, copy that information into a factory that produces your domain model objects.
Often, your design will include some manifestation of the factory pattern that creates an aggregate from other information - you can often use a similar factory behind the facade of your repository to achieve the same results on a reload.