4 ms·
I think that most of the time event-sourcing will impact your model/business-logic layer, because you often want to capture the intent of changes, rather than c
by Terr_ 10y ago
I think that most of the time event-sourcing will impact your model/business-logic layer, because you often want to capture the intent of changes, rather than calculating a naive combined delta of all changes that occurred in memory.
If so, that means that instead of a CRUD interface like:
if(customer.getApprovalLevel() < 5){
customer.setApprovalLevel(5);
customer.setApprover(currentUser);
}
saveChangesSomehow(customer);
So you'll end up with an API that's a bit more CQS (no 'R' yet) with:
if(customer.getApprovalLevel() < 5){
customer.promoteApprovalLevel(5, currentUser);
}
saveChangesSomehow(customer);
That way you capture each change-event at the right granularity with the necessary data. Finally, CQRS comes into play because you want to do something with that rich event data, such as eagerly populating a table:
recentApprovals = getRecentApprovals();
if(recentApprovals.length() > 0){
sendApprovalAuditReport(recentApprovals);
}