Injectors¶
uzi.injectors
¶
Injector
¶
Bases: ReadonlyDict[T_Injectable, Callable[[], T_Injected]]
An isolated dependency injection context for a given Scope
.
Attributes:
Name | Type | Description |
---|---|---|
graph |
DepGraph
|
the dependency graph for this injector |
parent |
Injector
|
a parent injector to provide missing dependencies. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph |
DepGraph
|
the dependency graph for this injector |
required |
parent |
Injector
|
a parent injector to provide missing dependencies. |
required |
name() -> str
property
¶
The name of the scope. Usually returns the injector's scope.name
NullInjector
¶
Bases: Injector
A 'noop' Injector
used as the parent of root injectors.
Attributes:
Name | Type | Description |
---|---|---|
scope |
NullScope
|
the scope |
parent |
None
|
The parent injector |
_InjectorExitStack
¶
Bases: list[tuple[bool, _T_Fn]]
Async context manager for dynamic management of a stack of exit callbacks.
For example
async with AsyncExitStack() as stack: connections = [await stack.enter_async_context(get_connection()) for i in range(5)] # All opened connections will automatically be released at the # end of the async with statement, even if attempts to open a # connection later in the list raise an exception.
push(exit: _T) -> _T
¶
Registers a callback with the standard exit method signature.
Can suppress exceptions the same way exit method can. Also accepts any object with an exit method (registering a call to the method instead of the object itself).
enter(cm)
¶
Enters the supplied context manager.
If successful, also pushes its exit method as a callback and returns the result of the enter method.
callback(/, callback: _T_Fn, *args, **kwds) -> _T_Fn
¶
Registers an arbitrary callback and arguments.
Cannot suppress exceptions.
close()
¶
Immediately unwind the context stack.
enter_async(cm)
async
¶
Enters the supplied async context manager.
If successful, also pushes its aexit method as a callback and returns the result of the aenter method.
push_async_exit(exit)
¶
Registers a coroutine function with the standard aexit method signature.
Can suppress exceptions the same way aexit method can. Also accepts any object with an aexit method (registering a call to the method instead of the object itself).
callback_async(/, callback, *args, **kwds)
¶
Registers an arbitrary coroutine function and arguments.
Cannot suppress exceptions.
aclose()
async
¶
Immediately unwind the context stack.
_push_async_cm_exit(cm, cm_exit)
¶
Helper to correctly register coroutine function to aexit method.