Skip to main content

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")

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.2.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

explicit_di-0.2.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file explicit_di-0.2.0.tar.gz.

File metadata

  • Download URL: explicit_di-0.2.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for explicit_di-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1bd5e17162cd4590f6c5593fdd0a09740e889dcf9132d49217dd4c4a00b96dd7
MD5 e2fe6659e72837592d040e3281987482
BLAKE2b-256 9001b18c2ddb3967ed46dc42c8eb41844d46f0fa760ff9bf6faf9de4a7843a4d

See more details on using hashes here.

File details

Details for the file explicit_di-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: explicit_di-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for explicit_di-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70fb4e9f4920778181bc2e83314d06a1da7225f7a1ae11b5f5c05ae3b9157447
MD5 2e70a93b35dbc2a23afb25881990b315
BLAKE2b-256 92cb177f8009226b5f494d715088b0902ea9541eba572917ef2d54cc36a9d1f6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page