Publishing events from a command handler defined in an Aggregate ?

Hi!

I would like to know if it make sense to publish events from an Aggregate ? And if yes, how should I do that ?

Actually, I can already publish events from a separate command handler, but from an aggregate I don’t have access to the event bus (didn’t find any way to get/inject its reference).

Thanks a lot for your help,
Octave

Hi,

the primary purpose of the command model is to publish event, so yes, it definitely does make sense. You should use the apply method, as described in the ref guide: https://docs.axonframework.org/part-ii-domain-logic/command-model#aggregate-implementations

Cheers,

Allard