Services
When an operation does not conceptually belong to any object. Following the natural contours of the problem, you can implement these operations in services. They are by essence stateless,
Typical sequence of a service
- Argument translation: the arguments of the method call are translated into domain objects;
- Cross-Entity constraint protection: cross-Entity business constraints are enforced;
- Entity manipulation: the relevant piece of business logic is executed on a specific Entity;
- Publishing the changes: resulting changes are published outside the Service boundaries, i.e. though events
- Responding to the Interface: the outcome of the method call is communicated back to the Interface. A Result is a container object which carries information about the outcome of an operation inside your Service.
What if anything goes wrong?
If the operation was not successful, the Service still returns a Result object. But in this case the object will wrap the exception(s) that occurred inside the Service method call.
In no case a Service method should let an exception escape outside of its box.