dependencies module¶
-
class
micro_framework.dependencies.Config¶ Bases:
micro_framework.dependencies.DependencyReturns the Runner Configuration.
-
async
get_dependency(worker: micro_framework.workers.Worker)¶ Injects the dependency that will be passed to the Target Function.
-
async
-
class
micro_framework.dependencies.Dependency¶ Bases:
micro_framework.extensions.ExtensionKind of extension that injects a dependency into the worker target.
The Dependency instance will be used by multiple workers so it is not recommended to store states to be used between the methods calls unless it is desirable to share this states between all workers of the same Route.
If you wish to store some values to be used between the methods in the same worker, use the worker instance passed.
The Dependency Life-Cycle is:
###### Main Process/Thread #########
- setup_dependency:
.Do anything that might be needed before actually creating the injected dependency.
- get_dependency:
.Returns the dependency to be injected
###### Worker Process/Thread ########
Run the Target Function/Method passing the injected dependency
###### Main Process/Thread #########
Attribute the result/exception to the worker class
- after_call:
.After the worker is executed, we call this method passing the worker and the result + exception from that call.
-
async
after_call(worker: micro_framework.workers.Worker, result: Any, exc: Exception)¶ Cleanup after the function has finished or raised.
-
async
bind(runner, parent=None)¶ Binds the extension to the service runner and parent. :param Runner runner: Service Runner
-
async
get_dependency(worker: micro_framework.workers.Worker) → Callable¶ Injects the dependency that will be passed to the Target Function.
-
async
setup_dependency(worker: micro_framework.workers.Worker)¶ Do any setup necessary before the dependency injection.
-
micro_framework.dependencies.inject(**dependencies)¶