Services — The Complete DI Pattern
The previous chapters established the building blocks: Tags (identities), Context (the environment), and Layers (constructors). Now we put them together into the complete Service pattern.
A Service in id_effect is the combination of:
- A trait defining the interface
- A tag identifying it in the environment
- One or more implementations (production and test)
- A layer that wires an implementation into the environment
This is the full dependency injection story. By the end of this chapter you'll have a working multi-service application wired entirely at compile time.
The sections Tokio bridge through Logging extend the same pattern to workspace integration crates: how you run effects on Tokio, swap platform and HTTP implementations, host handlers under Axum / Tower, and inject configuration and logging as services. Read them in order when wiring a production binary.