Skip to main content

No project description provided

Project description

Explicit DI

A library for explicit Dependency Injection

Tests pypi versions Docs license


Documentation: https://depeche-py.github.io/explicit-di/

Source code: https://github.com/depeche-py/explicit-di


Explicit DI is modern Python library for explicit Dependency Injection

Requirements

Python 3.9+

Installation

pip install explicit-di
# OR
poetry add explicit-di

Example

import explicit_di as _di


class A:
    pass


class B:
    def __init__(self, a: A, config : str):
        self.config = config
        self.a = a


class C:
    def __init__(self, b: B):
        self.b = b


def create_b(a: A):
    return B(a=a, config="foo")


def function_with_dependencies(one : int, two : str, my_c : C):
    print(my_c)


def main():
    container = _di.Container()
    container.register(A)
    container.register(B, create_b)
    container.register(C)

    b = container.resolve(B)
    assert isinstance(b, B)

    container.inject(function_with_dependencies, one=1, two="two")

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

explicit_di-0.1.2.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

explicit_di-0.1.2-py3-none-any.whl (3.8 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