Hi,
it’s not really clear to me how ‘H’ executes the intent of C. That’s really the job of A. Or is the handler a command handler inside the aggregate?
Actually I’m banging my head against several walls with this. Basically the question is, where should I put the “real” work inside the architecture? Aggregates, EventHandlers, CommandHandlers, Sagas? I actually already did it in several ways but none feel “natural” to me and they feel too complex… Let me try one example with my “audit” prototype: after the Aggregate is created with a CreateAudit (that only sets it’s Id) the user invokes a StartAudit
`
@CommandHandler
public Object startAudit(AuditStartCommand command) throws Exception {
Object audit = getAuditObject(command.getId()
);
apply(new AuditStartedEvent(command.getId(), audit));
return audit ;
}
@EventSourcingHandler
public void on(AuditStartedEvent event) throws Exception {
this.state = “STARTED”;
this.audit = event.getData();
}
`
So the question is, where that getAuditObject(Id
)`` gets it’s data from:
A injected service bean?
`
private Object getAuditObject(String id) {
return service.get(id);
}
`
Dispatch it as a command?
`
private Object getAuditObject(String id) {
return commandGateway.sendAndWait(new RetrieveAuditObject(id));
}
`
Dispatch it as a event?
private Object getAuditObject(String id) { eventTemplate.publishEvent(new RetrieveAuditObject(id));
return something…`
``}
`
This last one doesn’t look too useful, but what if I actually need to model this action as a Saga?
Actually, Sagas is what I’m struggling now, but I’ll write another post about it.
Once again, thanks for your great support.
Cheers.