Domain Service

The actions in some domain services are verbs that do not seem to belong to any object. They represent an important behavior in the field, so they cannot be ignored or simply merged into an entity or value object. When such behavior is identified from the domain, the recommended practice is to declare it as a service. Such objects no longer have a built-in state, their role is only to provide corresponding functions for the domain. Service is often named after an activity, not Entity.

For example, in the example of bank transfer, the behavior of transfer is a very important domain concept, but it occurs between two accounts, and the attribution account Entity is not appropriate, because an account Entity does not need to be associated with what it needs to transfer Account Entity. In this case, it is more appropriate to use MoneyTransferDomainService. To identify the domain service, it mainly depends on whether it meets the following three characteristics.

  1. The operations performed by the service represent a domain concept, which cannot naturally belong to an entity or value object.
  2. The operation being performed involves other objects in the domain
  3. The operation is stateless.

Guess you like

Origin blog.csdn.net/gou553323/article/details/112970925