syringe
This module provides an extremely simple utility for dependency injection.
It's made up of a single singleton class that provides a directory for the dependencies. The dependencies are stored in a dictionary and can be overridden or popped from the directory.
Usage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
| ATTRIBUTE | DESCRIPTION |
|---|---|
Inject |
The singleton instance of
|
Attributes
Inject = _Inject()
module-attribute
The singleton instance of _Inject, the only public member of this module.
Classes
_Inject
Injection class
This is a private class that is never directly instantiated.
| ATTRIBUTE | DESCRIPTION |
|---|---|
_dependencies |
The dependency directory |
| METHOD | DESCRIPTION |
|---|---|
__call__ |
Call the dependency |
override |
Override dependency |
pop |
Remove the dependency from the directory |
Source code in fractal_server/syringe.py
Methods:
__call__(_callable)
classmethod
Call the dependency
| PARAMETER | DESCRIPTION |
|---|---|
|
Callable dependency object
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
T
|
The output of calling |
Source code in fractal_server/syringe.py
override(_callable, value)
classmethod
pop(_callable)
classmethod
Remove the dependency from the directory
| PARAMETER | DESCRIPTION |
|---|---|
|
Callable dependency object
TYPE:
|