There are times user did an operation by mistake. Then application need provided a feature to let him cancel the operation he did. In cqrs world, we need have an event for that cancel operation.
Lets’s say because of XOperation, 5 fields of aggregate changed. Then after cancel XOperation, we expect the 5 fields of aggregate change backed to prior value, the view(read model) change back to prior value. Here comes the question:
Where can I get the prior value for the view(read model)?
Should I just put all the 5 fields and its prior value in the XOperationCancelledEvent? Or I design the view very careful, and lets the view capable of get the prior value from the view itself?
If I put 5 fields and it’s prior value in the XOperationCancelledEvent,Then there will be a chance that in future 6 fields(a new field defined because new business rule) need be changed back by this event. Then we may need a way(upcasting/fixing) to add that new fields to those “XOperationCancelledEvent” in the event store.
if we make the view capable of got the prior value, then there must be a lot of duplicated logic with the domain.
Seems neither way is perfect. So I start to wondering(am i crazy?), what if we make the aggregate fields expose to outside of domain (read only public getter), and read model can access those property to update the view?