An application service coordinates an application operation across repositories, validators, and domain objects. It controls the flow of a request—load data, reject invalid input, invoke domain behavior, and return or raise the result—without owning the business rules themselves. Keeping that control flow separate from domain logic makes a growing design easier to change and test. section 3.2.4
Coordinate enrollment without absorbing its rules
An add-employee operation loads an offering and employee, validates the request, then calls offering.addEmployee(employee). The service prevents direct access to the operation, while the validator holds rules such as capacity, repeat-participation limits, and duplicate enrollment. The service is therefore an orchestrator, not the place to decide those rules. section 3.2.4 section 3.2.4
Listing 3.5 AddEmployeeToOfferingService class
class AddEmployeeToOfferingService {
private OfferingRepository offerings;
private EmployeeRepository employees;
private AddEmployeeToOfferingValidator validator;
public void addEmployee(int offeringId, int employeeId) {
var offering = offerings.findById(offeringId);
var employee = employees.findById(employeeId);
if(offering == null || employe == null) #1
throw new InvalidRequestException(
"Offering and employee IDs should be valid");
var validation = validator.validate(offering, employee); #2
if(validation.hasErrors()) { #3
throw new ValidationException(validation);
}
offering.addEmployee(employee); #4
}
}
Trace the boundary: the service retrieves objects, checks validation results, and delegates the state change to the offering. section 3.2.4
Do not move domain invariants into a service merely to avoid loading aggregate state. A cancellation service that directly cancels an enrollment and increments available spots weakens the aggregate root’s control and can leave loaded objects inconsistent. When performance pressure changes the design, refactor deliberately: keep the service coordinating the cancellation and move availability calculation to an appropriate repository query rather than exposing a mutable spot counter. section 6.2.2 section 6.2.2
Listing 6.5 CancelEnrollmentService application service
class CancelEnrollmentService {
private OfferingRepository offerings;
private EnrollmentRepository enrollments;
public void cancel(int offeringId, int employeeId) { #1
if(offeringId==null || employeeId==null)
throw new InvalidArgumentException();
Offering offering = offerings.getById(offeringId);
if(offering == null)
throw new OfferingDoesntExistException();
Enrollment enrollment =
offerings.getEnrollment(offeringId, employeeId);
if(enrollment == null)
throw new EnrollmentDoesntExistException();
Calendar now = Calendar.getInstance();
enrollment.cancel(now); #2
}
}
class Offering { #3
// private int availableSpots;
// public void cancel(Enrollment enrollmentToCancel) { ... }
}
Compare this cancellation flow with a service that increments spots directly: it coordinates lookup and cancellation while avoiding a public aggregate mutation. section 6.2.2
Use the distinction pragmatically:
- Start simply when an operation is small, even if one service temporarily mixes orchestration and rules. section 3.2.4
- Refactor once growing complexity makes the separation useful; place business rules in domain services or domain objects and retain coordination in the application service. section 3.2.4
- Protect aggregate invariants rather than exposing convenience methods that let callers alter related state independently. section 6.2.2


