Replies: 1 comment 3 replies
-
Domain Services are less frequently used than other DDD elements, that's why you don't see many examples online. I see it like this: imagine you have two (or more) entities, and you need to implement some new use case that involves both of those entities. You can't put this logic in one of them, because it will make them coupled. Here where Domain Services come into play, they will orchestrate those entities. Examples: Imagine that you are making an online shop and have an Now lets say you have a new requirement: when placing an order, if your customer matches some conditions, for example he has a A domain service can look like this: export class OrderDomainService {
applyDiscountsIfEligible(order: Order, customer: Customer) {
if (customer.isVIP() && customer.isOlderThanYears(3)) {
order.applyDiscount(10);
}
return order;
}
} This way you don't have to mix customers and orders into a single Entity, but orchestrate them using a Domain Service. There is no one rule fits all here, everything depends on the business logic that you are implementing. |
Beta Was this translation helpful? Give feedback.
-
As I delve into Domain-Driven Design, I've encountered Domain Services as a way to encapsulate domain logic that doesn't naturally fit within a single entity. However, I'm finding it challenging to identify scenarios where Domain Services should be used instead of other DDD concepts such as Domain Entities or Value Objects. The existing code samples and documentation I've come across do not provide clear and practical use cases that would help me better understand the concept.
I kindly request the community's assistance in shedding light on the following points:
I believe that having concrete examples and discussions around Domain Services will greatly enhance my understanding of this crucial aspect of Domain-Driven Design. Your insights and contributions would be invaluable in helping me and others grasp this concept more comprehensively.
Thank you for your time and assistance.
Beta Was this translation helpful? Give feedback.
All reactions