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

Hi,
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 https://blog.jayway.com/2013/06/20/dont-publish-domain-events-return-them/

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.

Cheers,

Allard

Hi Allard,
After reading your reply and https://blogs.msdn.microsoft.com/cesardelatorre/2017/02/07/domain-events-vs-integration-events-in-domain-driven-design-and-microservices-architectures/
I think you have made a good point, it makes sense apply domain events in Aggregate.

Thanks.