Can we publish events in application service instead of apply them in Aggregate

We are thinking of publishing events in application service instead of applying them in Aggregate, so the domain code won’t dependent on frameworks.
Is there any drawback of doing this? cause it seems not recommended in axon. And is eventbus.publish(GenericEventMessage.asEventMessage(event)) the same as AggregateLifecycle.apply(event)?

there’s some discussion about this approach

Best regards,

Hi Tian,

there is a different between apply() and eventBus.publish. The main difference being that the apply() method generates a DomainEventMessage, which also describes the aggregate that published the message. Of couse, you can just create a DomainEventMessage yourself and eventBus.publish() that instead.

I know of the Jayway article. The writer did a very good job at explicitly excluding the case where an aggregate is event sourced, because that’s exactly the case where things get very complicated. In fact, I don’t think this approach would be feasible in that case: sometimes, you want to make decisions based on the state after an event has been applied to an aggregate. That’s not possible of you can only provide events to apply as a return value.

Personally, I prefer “apply”, as the framework impact is minimal, and it’s a lot more expressive and explicit that any other API I have seen/attempted.



Hi Allard,
After reading your reply and
I think you have made a good point, it makes sense apply domain events in Aggregate.