returning domain events

336 views
Skip to first unread message

Alew

unread,
May 18, 2021, 10:58:45 AM5/18/21
to ddd...@googlegroups.com

Hi!

Why is the practice of returning events described in Don't publish Domain Events, return them! - blog. (jayway.com)  not widely used?

Thanks.

Harrison Brown

unread,
May 18, 2021, 11:05:40 AM5/18/21
to ddd...@googlegroups.com
We started by returning events, having read that post, but have since switched to publishing events via a static DomainEvents::publish(…) method from our aggregates because we found it was difficult to know the context from which an aggregate was going to be invoked. Sometimes they’re invoked directly from a command handler, sometimes from a domain service, sometimes from within another object via double dispatch, etc. Piping events back through those various pathways got very complex and we found it a lot easier to have a static class whose job was to collate all the events for a given request. 

This also makes it easier to write complex methods in aggregates. A method can do some logic, then raise an event, then do some more logic an optionally raise a second event, a third, etc. rather than having to keep track of events and remember return them at the end (or at multiple places if we’re doing an early return).

Harrison

Sent from my iPhone

On 18 May 2021, at 15:58, Alew <ale...@gmail.com> wrote:



Hi!

Why is the practice of returning events described in Don't publish Domain Events, return them! - blog. (jayway.com)  not widely used?

Thanks.

--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dddcqrs/ce42733d-b53e-a291-513e-c9e55d4b95fc%40gmail.com.

Mateusz Nowak

unread,
May 18, 2021, 4:24:55 PM5/18/21
to ddd...@googlegroups.com
I'm using this approach a lot and it's very easy to follow, especially with functional programming. It gives you good, pure functions (without side effects like invoking static method) easy to test. You test just what should be returned by the aggregate method.

Alew, do you use Event Sourcing or not? My usage of this depends on the answer. 

Reply all
Reply to author
Forward
0 new messages