Python-dependency-injection is a simple yet powerful mini-framework for dependency injection in Python
Project description
Python-dependency-injection
Python-dependency-injection is a simple yet powerful mini-framework for dependency injection in Python
Installation
Use the package manager pip to install Python-dependency-injection.
pip install Python-dependency-injection
Usage
# this class will be injected
class InjectedClass:
def __init__(self):
self.message: str = ' from InjectedClass'
def foo(self, str1: str) -> str:
return str1 + self.message
# class objects will be injected to
from dependency_injection.decorators.autowired import autowired
class TestSingletonInjection:
@autowired()
def __init__(self, my_name: str, injected_class: InjectedClass):
self.injected_class = injected_class
self.my_name = my_name
def boo(self) -> str:
return self.injected_class.foo('hello TestClassSingleton')
# class objects will be injected to
from dependency_injection.decorators.autowired import autowired
from dependency_injection.decorators.autowired_enums import AutoWiredType
class TestSingleCallInjection:
@autowired(AutoWiredType.SINGLECALL)
def __init__(self, my_name: str, injected_class: InjectedClass):
self.injected_class = injected_class
self.my_name = my_name
def boo(self) -> str:
return self.injected_class.foo('hello TestClassSinglecall')
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.
##License MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for python-dependency-injection-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19fe984012cf2d486b8a2c8dab8f924297914f0aa3504bbba3512d094a4d7e7c |
|
MD5 | 7b5684c88bb43b77039be358a85d32fe |
|
BLAKE2b-256 | 7e87caf3a831cf2f615bb57e08ded9e4259e0593f3c2c82aeae324d8f915a5f2 |
Close
Hashes for python_dependency_injection-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdc7e451c46371e8533ce8573c2dd52ed58551c42d52156ac7b744fb445755e3 |
|
MD5 | 78dd6163e7fe040836c307959341521b |
|
BLAKE2b-256 | f5f960f5ffe0ff3d8569e0219ecfcc7fb893c14e16c14821a5f6f3d044a96b6a |