Core Concepts
Providers, modules, scopes, lifecycle and the container that wires them.
An application is a graph of providers grouped into modules. The container checks the whole graph when the application starts, builds the singletons in dependency order, and hands each request or job its own execution. Nothing constructs its own dependencies.
The parts, each with the page that covers it:
- A key is a type plus an optional qualifier:
PgPool, orPgPool @ Replica. Qualifiers are types, so there are no strings to misspell. - A binding says how to build the value behind a key: from a type, a value or a closure.
- An injection point is a field or parameter the container fills:
Dep<T>,Many<T>,Ext<T>(a value written into one execution, see Standalone executions),Option<..>. - A module declares imports, bindings, controllers and exports, and decides what leaves it.
- The graph is every module registered, frozen and validated.
wire()reports all of its problems in one pass. - An execution is one call: an HTTP request, a WebSocket message, an RPC call, or a job you open yourself.
The examples under examples/02-providers to examples/14-without-macros in the repository are the code behind these pages. Each is a runnable package with tests. Code blocks on these pages come from those examples, and the page names the example.
Providers
Declaring a provider, injecting it with Dep, and what a failing constructor does.
Traits and qualifiers
Binding a provider under a trait, and telling two instances of one type apart.
Collections and optional dependencies
Many<dyn T> for plugins, Option<Dep<T>> for what may be absent.
Scopes
Singleton, execution and transient: how long an instance lives.
Modules
Imports, exports and what a module can see.
Configured modules
Global modules, modules that take a value, and one module imported under two qualifiers.
Dynamic and lazy modules
Modules built at runtime, and modules loaded after startup.
Application phases
Builder, wire, connect, bind, listen, serve.
Lifecycle hooks
Init, bootstrap, destroy and shutdown hooks, and readiness checks.
Shutdown
Draining in-flight work, the shutdown timeout, and the report.
Standalone executions
Running a job or a command with no server.
The wiring report
Every startup refusal, and how the report reads.
Without macros
The value API the macros expand to.
Controllers and handlers belong to a transport and are covered with it: request lifecycle and HTTP servers.