Short answer: Only use Domain Service if you need that additional level of abstraction.
Long answer as follows.
From the documentation Domain Services #Introduction:
Creating a Domain Service is especially needed when;
- You implement a core domain logic that depends on some services (like repositories or other external services).
- The logic you need to implement is related to more than one aggregate/entity, so it doesn't properly fit in any of the aggregates.
Example from the documentation Domain Services #Introduction: When assigning an Issue to a User, check that the number of Issues assigned is not more than or equal to a certain number.
Example from the tutorial Part 6: Authors: Domain layer: When changing the Name of an Author, check that there is not already an author with the given name.
You could miss a check that is a core domain logic or business rule.
But generally, no problem. From the tutorial Part 6: Authors: Domain layer:
DDD tip: Do not introduce domain service methods unless they are really needed and perform some core business rules.
See examples in #1 and #4.
From the documentation Domain Services #Application Services vs Domain Services:
While both of Application Services and Domain Services implement the business rules, there are fundamental logical and formal differences;
- Application Services implement the use cases of the application (user interactions in a typical web application), while Domain Services implement the core, use case independent domain logic.
- Application Services get/return Data Transfer Objects, Domain Service methods typically get and return the domain objects (entities, value objects).
- Domain services are typically used by the Application Services or other Domain Services, while Application Services are used by the Presentation Layer or Client Applications.
From the tutorial Part 8: Author: Application Layer:
- Used the
AuthorManager
(domain service) to create a new author.- Used the
IAuthorRepository.InsertAsync
to insert the new author to the database.- Used the
ObjectMapper
to return anAuthorDto
representing the newly created author.DDD tip: Some developers may find useful to insert the new entity inside the
_authorManager.CreateAsync
. We think it is a better design to leave it to the application layer since it better knows when to insert it to the database (maybe it requires additional works on the entity before insert, which would require to an additional update if we perform the insert in the domain service). However, it is completely up to you.