How do you validate commands based on the aggregate state?

117 views
Skip to first unread message

Chirdeep Tomar

unread,
Feb 4, 2015, 12:26:57 PM2/4/15
to axonfr...@googlegroups.com
I would like to change the state of a property in my aggregate lets say called IsActive, I would like to set it to false if only if IsActive is currently true. How would do such sort of command validation? Do you query the Event Store for the current state of the aggregate or query the read store from the aggregate class? 

Also, I am going through some of the questions here and people are only changing the state in the read store without applying the event? why would you do that? Shouldn't both the states in read and event store match up at the end? 



Allard Buijze

unread,
Feb 5, 2015, 3:16:49 AM2/5/15
to Axon Framework Users
The only place where you can do that type of validation, is in the aggregate itself. The aggregates (in the command model) aren't allowed to expose their state, so there isn't any other place you can do it. The state maintained by the aggregate (which is initialized using events, when using event sourcing), should be sufficient to do this validation.

I don't think anyone changes the read model state without an event being applied. Events are applied in the command model, and then published to the read model updaters. They pick up those events and change the model accordingly.

Cheers,

Allard

On Wed, Feb 4, 2015 at 6:26 PM, Chirdeep Tomar <chirdee...@gmail.com> wrote:
I would like to change the state of a property in my aggregate lets say called IsActive, I would like to set it to false if only if IsActive is currently true. How would do such sort of command validation? Do you query the Event Store for the current state of the aggregate or query the read store from the aggregate class? 

Also, I am going through some of the questions here and people are only changing the state in the read store without applying the event? why would you do that? Shouldn't both the states in read and event store match up at the end? 



--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages