Decorators¶
Public decorators: provide, inject, ainject.
These decorators form the main user-facing API for FastDI and are documented so they render well under MkDocs.
ainject(container)
¶
Decorator for async call sites.
Compiles a plan and executes it iteratively in topological order. The
resulting wrapper preserves the original signature, resolving
Annotated[..., Depends(...)] parameters when missing before awaiting
the original function.
ainject_method(container)
¶
Decorator for async instance methods that need injection.
The resulting wrapper expects to be called as a bound method (i.e., with
self). Dependencies declared with Depends are injected and passed
positionally after self.
inject(container)
¶
Decorator for sync call sites.
Compiles and validates a plan at decoration time and executes the call via
the Rust core resolver. The resulting wrapper preserves the original
signature, filling Annotated[..., Depends(...)] parameters when they
are not provided explicitly.
inject_method(container)
¶
Decorator for sync instance methods that need injection.
The resulting wrapper expects to be called as a bound method (i.e., with
self). Dependencies declared with Depends are injected and passed
positionally after self.
provide(container, *, singleton=False, key=None, scope=None)
¶
Register a function as a provider.
The decorated function is returned unchanged, allowing direct invocation in tests if desired.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
Container
|
Target DI container where the provider will be registered. |
required |
singleton
|
bool
|
Cache result globally (Rust cache) on first computation. |
False
|
key
|
Key | None
|
Optional explicit registration key; by default derived from the function. |
None
|
scope
|
Scope | None
|
Optional Python-managed scope ("transient" or "request"). |
None
|