Skip to content
Ameen Abozaid
Planned lessonJNR-013-L03

Services: business logic and orchestration

  • Lesson 3 of 8
  • Junior
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 ResponseEntity or reads request headers.
  • Keep services stateless (JNR-010).
Draft outline details

Demonstration

java
@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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.