14 Nov 2023



Advanced

The Domain Services, Application Services, and Infrastructure services are three types of services that are used in software development. Each type of service has a different purpose and responsibility.

Domain Services

Domain Services encapsulate the business logic of an application. They are responsible for performing complex operations on the domain model, such as calculating discounts, validating orders, or generating reports. Domain Services are typically used by Application Services, but they may also be used directly by other Domain Services.

Application Services

Application Services provide a high-level abstraction for interacting with the domain model. They are responsible for coordinating the execution of multiple Domain Services and returning the results to the client. Application Services are typically exposed to the outside world through APIs or web controllers.

Infrastructure Services

Infrastructure Services provide the underlying infrastructure for the application, such as database access, messaging, and logging. They are typically hidden from the Application and Domain Services, which makes it easier to test and deploy the application independently of the underlying infrastructure.

The following table summarizes the key differences between Domain Services, Application Services, and Infrastructure Services:

TypePurposeResponsibility
Domain ServiceEncapsulates the business logic of an application.Performs complex operations on the domain model.
Application ServiceProvides a high-level abstraction for interacting with the domain model.Coordinates the execution of multiple Domain Services and returns the results to the client.
Infrastructure ServiceProvides the underlying infrastructure for the application.Provides database access, messaging, and logging.

Here are some examples of each type of service:

  • Domain Service: Calculate the total price of an order, validate the shipping address of a customer, or generate a report of sales by product category.
  • Application Service: Place an order, update a customer's profile, or get a list of all products in stock.
  • Infrastructure Service: Connect to a database, send an email, or log an error message.

Domain Services, Application Services, and Infrastructure Services are all important parts of a well-designed software application. By separating each type of service into its own layer, it is easier to develop, test, and deploy the application.

domain-driven-design-ddd
services
difference