How to choose between using a Domain Event, or letting the application layer orchestrate everything

Posted by Mr Happy on Programmers See other posts from Programmers or by Mr Happy
Published on 2012-10-11T12:04:26Z Indexed on 2012/10/11 15:48 UTC
Read the original article Hit count: 215

Filed under:
|
|

I'm setting my first steps into domain driven design, bought the blue book and all, and I find myself seeing three ways to implement a certain solution. For the record: I'm not using CQRS or Event Sourcing.

Let's say a user request comes into the application service layer. The business logic for that request is (for whatever reason) separated into a method on an entity, and a method on a domain service. How should I go about calling those methods?

The options I have gathered so far are:

  • Let the application service call both methods
  • Use method injection/double dispatch to inject the domain service into the entity, letting the entity do it's thing and then let it call the method of the domain service (or the other way around, letting the domain service call the method on the entity)
  • Raise a domain event in the entity method, a handler of which calls the domain service. (The kind of domain events I'm talking about are: http://www.udidahan.com/2009/06/14/domain-events-salvation/)

I think these are all viable, but I'm unable to choose between them. I've been thinking about this a long time and I've come to a point where I no longer see the semantic differences between the three. Do you know of some guidelines when to use what?

© Programmers or respective owner

Related posts about c#

Related posts about patterns-and-practices