Search code examples
c#cqrs

In CQRS pattern, should work go in domain services or command handlers


Should domain services inject other domain services and do work between each other and have the commandhandler be dumb. OR, should the domain services be dumb (only be used to interface the repository barrier) and the majority of work be done in commandhandler's? What is best practices here...


Solution

  • I would say add ALL business logic inside domain objects (and also domain services if the functionality doesn't fit into an object) and use commandhandlers for things like:

    • instantiate domain objects and run methods on them,
    • run methods on domain services,
    • provide dependencies to domain objects,
    • manage database transactions,
    • ...

    You can check out the onion architecture, I guess your domainservices are inside Domain Model and commandhandlers inside Application Services.