Application Service fulfills the commands issued by clients ( ie presentation layer ) by making and coordinating calls to the Workflows, Infrastructure Services, Domain Services and Domain Entities.
Is it a common practice to also have few Domain Services that do similar job as Application Services, meaning they also make and coordinate calls, only difference being they do it at a more fine-grained level ( ie they only make and coordinate calls to other Domain Services and Domain Objects )?
If yes, any ideas how fine-grained should these Domain Services be?
Thank you
Domain Services contain domain logic that doesn’t particularly fit into any Entity, or that spans across several entities.
One often quoted example is a FundsTransferService. Transferring funds doesn’t seem like the responsibility of the BankAccount entity, because that would mean the source account can modify the target account’s balance (or the other way around) which seems awkward and might be dangerous. A dedicated TransferFunds() method in a FundsTransferService allows for better separation of concerns and channels all funds movements in a single place.
In that regard, you could say Domain Services coordinate calls on entities and other services, but not in the same sense that Application layer services do IMO. Oftentimes, Application layer services are just boilerplate procedural code while Domain services contain real business rules.
I wouldn’t say Domain services are more fine-grained than Application services. They are essentially just in different layers. It’s like saying that a Repository is finer grained than a Controller… usually granularity is a measure of to what extent one cohesive operation is split up in smaller parts vs just a big procedure.