Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Domain Driven Design: Domain Service, Application Service

Can someone explain the difference between domain and application services by providing some examples? And, if a service is a domain service, would I put the actual implementation of this service within the domain assembly and if so, would I also inject repositories into that domain service? Some info would be really helpful.

like image 750
Chris Avatar asked Feb 15 '10 20:02

Chris


People also ask

What is the difference between domain service and application service?

The main difference between them is that domain services hold domain logic whereas application services don't. As we discussed in a previous post, domain logic is everything that is related to business decisions.

What is domain-driven design services?

Domain Services (or just Services in DDD) is used to perform domain operations and business rules. In his DDD book, Eric Evans describes a good Service in three characteristics: The operation relates to a domain concept that is not a natural part of an Entity or Value Object.

When should you use a domain service?

You only need a Domain Service if the piece of domain logic you are modelling does not naturally fit on any Domain Object. A common scenario for this is when the responsibility of the action does not naturally fit on any particular object or if it requires multiple Domain Objects in order to co-ordinate the action.

What is domain-driven design example?

An aggregate is a domain-driven design pattern. It's a cluster of domain objects (e.g. entity, value object), treated as one single unit. A car is a good example. It consists of wheels, lights and an engine.


1 Answers

Services come in 3 flavours: Domain Services, Application Services, and Infrastructure Services.

  • Domain Services : Encapsulates business logic that doesn't naturally fit within a domain object, and are NOT typical CRUD operations – those would belong to a Repository.
  • Application Services : Used by external consumers to talk to your system (think Web Services). If consumers need access to CRUD operations, they would be exposed here.
  • Infrastructure Services : Used to abstract technical concerns (e.g. MSMQ, email provider, etc).

Keeping Domain Services along with your Domain Objects is sensible – they are all focused on domain logic. And yes, you can inject Repositories into your Services.

Application Services will typically use both Domain Services and Repositories to deal with external requests.

Hope that helps!

like image 143
Vijay Patel Avatar answered Oct 04 '22 13:10

Vijay Patel