Hello,
I’m wondering whether it is possible to have the same command handled in a constructor and a method?
As an example, let’s imagine an aggregate made of:
`
@CommandHandler
public TestAggregate(CustomerCommand command) {
apply(new CustomerCreatedEvent(command.getId(), command.getName()));
}
@CommandHandler
public void on(CustomerCommand command) {
apply(new CustomerUpdatedEvent(command.getId(), command.getName()));
}
`
What I expect is:
- If the aggregate instance does not exist, the command is caught by the constructor which create an aggregate instance
- Otherwise, the command is caught by the on() method to enrich the existing aggregate instance
Is that something possible in Axon? It seems the command is always caught by the constructor even in such cases:
fixture. given(new CustomerCreatedEvent("001", "a")). when(new CustomerCommand("001", "b")). expectEvents(new CustomerUpdatedEvent("001", "b"));
Thanks