liveBook · Manning

Application service

As explained in Unit Testing Principles, Practices, and Patterns

An application service is a service that coordinates application operations and connects a functional core with external clients and side-effecting infrastructure.

An application service coordinates application operations between a domain model and the external world. It provides an entry point for clients, retrieves and materializes domain objects, invokes domain behavior, persists results, and coordinates side effects. section 5.3 section 6.4

In hexagonal architecture, the application service sits above the domain layer. Dependencies flow toward the domain: domain classes contain business logic and remain independent of databases, message buses, filesystems, and other out-of-process systems. External applications connect through interfaces maintained by the application-services layer. section 5.5 section 7.2

Keep the service orchestral rather than computational:

  • Load the required data through persistence or gateway collaborators. section 5.3
  • Pass domain objects and plain values to domain operations; move complex reconstruction and business rules into factories or domain classes. section 7.2
  • Persist changed domain state and trigger external effects only when the use case requires them. section 5.3 section 7.2
  • Prefer tests that verify the use case through observable outputs or boundary effects; mocking intra-system calls couples tests to implementation details. section 5.5 section 6.4

Gluing a functional core to a mutable shell

An audit application separates the decision from filesystem effects. AuditManager receives FileContent values and returns a FileUpdate; Persister reads files and applies that update. ApplicationService reads the directory, passes the files and visitor record to AuditManager, then asks Persister to apply the result. The service remains a thin use-case entry point, while output-based tests can assert the selected filename and content without filesystem mocks. section 6.4

Figure 5.8. A typical application consists of a domain layer and an application services layer. The domain layer contains the application’s business logic; application services tie that logic to business use cases.

Use the layered diagram to distinguish domain business logic from the application-services layer that ties it to business use cases. section 5.3

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Explains layering, dependency direction, orchestration boundaries, refactoring, and output-based testing, stopping short of implementation-specific infrastructure design.
Examples
Uses user renaming, customer purchasing, and filesystem-based audit recording to demonstrate orchestration and testing trade-offs.
What it assumes
Assumes familiarity with domain objects and external dependencies while demonstrating separation of business logic from infrastructure coordination.
What you can do after
Build it from scratch as a thin use-case entry point that coordinates domain operations, persistence, and justified external effects.
How it connects
Connects domain model, hexagonal architecture, functional core, mutable shell, external systems, mocks, and test fragility.

Also explained in

Compare how 2 books explain application service →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.