SteelReed

Search

Search posts, questions…

OOP & DesignQuestion 40 / 42

Middle

How does an application service differ from a domain service, and where should repository interfaces live?

Short answer

An application service orchestrates a use case (load, call the domain, save, transaction); it is thin and holds no rules. A domain service holds business rules that belong to no single entity, and knows nothing about transactions or HTTP.

load, saveControllerApplication servicetransaction, authorizationRepository interfacein the domain layerDomain servicecross-aggregate rulesAggregate

3 points to say:

  1. Application service: orchestrates, thin, knows transactions, authorization, publishing events.
  2. Domain service: rules spanning several aggregates (a transfer fee between two accounts); put logic in entities/value objects first.
  3. The repository interface lives in the domain, next to the aggregate it stores; the implementation lives in infrastructure.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.