Contents
Where does aggregate root fit in CQRS architecture?
Within a CRM application, the equivalent of a ‘line’ would not be an entity. The ‘line’ may be a ‘ Value Object ‘ attached to a customer who is in turn an entity. If you are new to CQRS you may want to see where an Aggregate Root fits into a typcial CQRS architecture. You can do that here.
Which is an entity in an aggregate root?
The job of enforcing the invariants within a bounded context is that of the Aggregate Root which is also an Entity. Entity: An entity is an object that differs by ID. Take for example, a telephone company. Within that context, a ‘line’ identified by a telephone number would be an entity. The context is important.
Why is aggregate root important in Event Sourcing?
On success the aggregate generates the events. You can therefore be confident that the events, when played back in order, will return the aggregate to its current state. While small and relatively simple, this abstract class is at the heart of CQRS and event sourcing.
Where are the changes stored in aggregate root?
Once an aggregate has completed a command (more on this further down) it will store up the changes in the _changes list. These changes are in the form of an Event or description of what has just happened. On completion of the command, the outside system would then request any uncommitted changes. That list would then saved.
How does aggregate root get list of events?
The external service retrieves the list of previous events. Given the aggregate is an entity it is a trivial ‘get by id’ or ‘SELECT * FROM X WHERE ID = …’ database query. The outside service would then pass in the events to the LoadFromHistory method which in turn would apply each event to it’s self.
What’s the best way to build an aggregate root?
This is just one way to build an Aggregate Root. If you are looking for a non-CQRS apporach to building an Aggregate Root I would recommend an article by Udi Dahan called “Don’t Create Aggregate Roots” ( http://www.udidahan.com/2009/06/29/dont-create-aggregate-roots/ ). I hope you found that post helpful.