Services: business logic and orchestration
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
place rules and workflows in the service.
Planned topics
- A service holds business rules and coordinates repositories and other services.
- It works with domain objects and plain values, not HTTP types.
- A service never returns
ResponseEntityor reads request headers. - Keep services stateless (JNR-010).
Draft outline details
Demonstration
@Service
class ProductService {
private final ProductRepository repo;
ProductService(ProductRepository repo) { this.repo = repo; }
ProductResponse get(long id) {
return ProductMapper.toResponse(repo.findById(id).orElseThrow(() -> new ProductNotFound(id)));
}
}Check your understanding
Should a service return ResponseEntity?
Show answer
No; that is an HTTP concern for the edge.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.