Search code examples
domain-driven-designdomainservices

Injecting domain service into the AggregateRoots in DDD


The commonly known advise in DDD is that an Aggregate Roots don't user a domain service. The domain service is to coordinate two Aggregate Roots to achieve a behavior.

It really surprised me when I saw this blog written by Rinat Abdullin with the title Building Blocks Of CQRS. Under the Domain Service section, you will read that a domain service is injected to an Aggregate Root.

Can an Aggregate Root accept a domain service?


Solution

  • Please, disregard that article. It was written a long time ago and is plain wrong. If implementing a module with AggregateRoot and DomainService patterns, I would recommend to have a higher logic (e.g. request handler) which is responsible for:

    1. Loading the aggregate
    2. Performing calculations with the help of domain services
    3. Mutating the aggregate state accordingly.