Skip to main content

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

python-dependency-injection-0.0.1.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

python_dependency_injection-0.0.1-py3-none-any.whl (12.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page