A dependency injection module using python 3 annotations
How to use
from py3njection import inject from some_package import ClassToInject class Demo: @inject def __init__(self, object_to_use: ClassToInject): self.dependency = object_to_use demo = Demo()
How does it work ?
The decorator @inject looks for any annotated method/function parameters (return annotation excluded).
It creates a new object from the specified class if no object is already provided.
How to install
It’s available on PyPI !
pip install py3injection
Unit tests come easy to set up (unless you have too many dependencies, but that would be a code smell, right ?). Juste specify mock instances at your object creation. Examples will come later.
This also means the injected object could also have some of its members injected too at their initialization !
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
py3njection-1.2.tar.gz (2.0 kB view hashes)