Core concepts¶
This section is the mental model behind diwire. If you prefer learning by doing:
For FastAPI: start with Quick start (FastAPI)
For plain Python: start with the Tutorial (runnable examples) tutorial
Use these pages as the “why it works” reference.
Recommended order¶
Container - auto-wiring, what gets resolved, and how keys work
Registration - explicit registration, decorators, and interfaces
Lifetimes - transient vs scoped (root-scoped scoped behaves like singleton)
Scopes & cleanup - request-like scopes and deterministic cleanup
Function injection - injecting into functions with
Injected[T]Components (named registrations) - multiple implementations via
Component("name")Open generics - open generic registrations and type-safe resolution
Async - async factories, async cleanup, and
aresolve()resolver_context - global context container for framework integration
Compilation - precomputing the graph for speed
Errors - common error modes and how to debug them
Integrations - dataclasses/namedtuple/pydantic/attrs/msgspec notes