I’m curious as to why the constructor cannot set its properties from the command and remove the need for the @EventHandler entirely. Is there a strategic or technical reason for this?
There’s a technical reason. If the aggregate is event sourced, it will be recreated by applying the events sequentially. If the assignments aren’t in an event handler, the fields will not be set when the aggregate is rebuilt.
thanks for the feedback. I will add a little explanation to the getting started guide.
Basically, the rule is:
command handlers make decisions
event handlers change the state
Neither of the two does he other things. Once command handlers change state, that change will not be reflected when the aggregated is loaded back in. Axon’s GivenWhenThenTestFixture will detect this, and fail the test.