In DDD, we use a few different types of services to help us organize our code. These are application services, domain services, and infrastructure services. In this section, we will discuss all three services and when they are useful, starting with the domain service.
Domain services are stateless operations within a domain that complete a certain activity. Sometimes, we will come across processes we cannot find a good way to model in an entity or value object; in these cases, it’s a good idea to use a domain service.
It is particularly tricky to outline rules to use domain services; however, some things that you should look out for are the following:
- The code you are about to write performs a significant piece of business logic within one domain
- You are transforming one domain object into another
- You are taking the properties of two or more domain objects to calculate a value
Services should always be expressed...