can I ask if applying an event in another event handler common pattern? Or should it be avoided as much as possible? Maybe I am little confused about whole CQRS concept :(, but I am trying to implement something what is really driven by events. I think CQRS and ES is
perfect fit but maybe I am wrong. Is it completely wrong that my aggregate state is internally driven by events?
I try to describe my problem a little. I have Player aggregate and I send command to that player: new ChangeExperience(playerId, +1500) … now, when command handler calls PlayerAggregate.changeExperience(amount) methods, following events are
applied (alignment means event nesting)
-> ExperienceChanged(playerId, +1500) // current experience is 1500 and for next level is needed 100xp, so levelUp is raised and -100xp is subtracted
-> LevelUp(playerId, +1) // when player levelUp to 1st level, some his stats are increased
-> VitalityChanged(playerId, +2)
-> StrengthChanged(playerId, +1)
-> ExperienceChanged(playerId, -100) // curren experience is 1400 and for next level is needed 200px
->LevelUp(playerId, +1) // when player reaches level 2, he learns a new spell fireball
-> SpellLearned(playerId, “fireball”)
-> ExperienceChanged(playerId, -200)
… and so on
So basically, one command can cause a lot of events and each event can starts another events. All this process should be consistent and done in single unit of work. Do you think that CQRS and ES is absolutely wrong choice here? If so, can someone recommend me
some architecture/technology/framework etc… where something like this can be easily implemented? Thank you very much.
PS. I am sorry that there is more similar post from me, but I am hopeless.