Socket
Socket
Sign inDemoInstall

explicit-di

Package Overview
Dependencies
0
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    explicit-di


Maintainers
1

Readme

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

Keywords

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc