provider
Classes:
-
AsyncProvider
–A provider for a dependency.
-
SyncProvider
–A provider for a dependency.
Functions:
-
asynccontextmanager
–Create a provider from the given async iterator function.
-
asyncfunction
–Create a provider from the given coroutine.
-
contextmanager
–Create a provider from the given iterator function.
-
function
–Create a provider from the given function.
Attributes:
Provider
module-attribute
Provider: TypeAlias = (
"SyncProvider[P, R] | AsyncProvider[P, R]"
)
A provider for a dependency.
AsyncProvider
AsyncProvider(
producer: AsyncContextManagerCallable[P, R],
provides: Hint | InferHint,
dependencies: HintMap,
)
Bases: Generic[P, R]
, _BaseProvider[R]
A provider for a dependency.
Methods:
-
bind
–Inject the dependencies and produce the dependency.
bind
bind(
*args: args, **kwargs: kwargs
) -> AsyncProvider[[], R]
Inject the dependencies and produce the dependency.
SyncProvider
SyncProvider(
producer: ContextManagerCallable[P, R],
provides: Hint | InferHint,
dependencies: HintMap,
)
Bases: Generic[P, R]
, _BaseProvider[R]
A provider for a dependency.
Methods:
-
bind
–Inject the dependencies and produce the dependency.
bind
bind(*args: args, **kwargs: kwargs) -> SyncProvider[[], R]
Inject the dependencies and produce the dependency.
asynccontextmanager
asynccontextmanager(
func: AsyncIteratorCallable[P, R],
*,
requires: HintMap | HintSeq | None = None,
provides: Hint | InferHint | None = None
) -> AsyncProvider[P, R]
Create a provider from the given async iterator function.
Parameters:
-
func
AsyncIteratorCallable[P, R]
) –The function to create a provider from.
-
requires
HintMap | HintSeq | None
, default:None
) –The dependencies of the function (infered if not provided).
-
provides
Hint | InferHint | None
, default:None
) –The type that the function provides (infered if not provided).
asyncfunction
asyncfunction(
func: Callable[P, Awaitable[R]],
*,
requires: HintMap | HintSeq | None = None,
provides: Hint | InferHint | None = None
) -> AsyncProvider[P, R]
Create a provider from the given coroutine.
Parameters:
-
func
Callable[P, Awaitable[R]]
) –The function to create a provider from.
-
requires
HintMap | HintSeq | None
, default:None
) –The dependencies of the function (infered if not provided).
-
provides
Hint | InferHint | None
, default:None
) –The type that the function provides (infered if not provided).
contextmanager
contextmanager(
func: IteratorCallable[P, R],
*,
requires: HintMap | HintSeq | None = None,
provides: Hint | InferHint | None = None
) -> SyncProvider[P, R]
Create a provider from the given iterator function.
Parameters:
-
func
IteratorCallable[P, R]
) –The function to create a provider from.
-
requires
HintMap | HintSeq | None
, default:None
) –The dependencies of the function (infered if not provided).
-
provides
Hint | InferHint | None
, default:None
) –The type that the function provides (infered if not provided).