Skip to main content

Dependency Injection for Humans

Project description

Dependencies

azure-devops-builds azure-devops-coverage pypi conda

Dependency Injection for Humans.

Documentation | Source Code | Task Tracker

Dependency Injection (or simply DI) is a great technique. By using it you can organize responsibilities in you codebase. Define high level policies and system behavior in one part. Delegate control to low level mechanisms in another part. Simple and powerful.

With help of DI you can use different parts of your system independently and combine their behavior really easy.

If you split logic and implementation into different classes, you will see how pleasant it becomes to change your system.

This tiny library helps you to connect parts of your system, in particular - to inject low level implementation into high level behavior.

Pros

  • Provide composition instead of inheritance.
  • Solves top-down architecture problems.
  • Boilerplate-free object hierarchies.
  • API entrypoints, admin panels, CLI commands are oneliners.

Example

Dependency injection without dependencies

>>> from app.robot import Robot, Servo, Amplifier, Controller, Settings

>>> robot = Robot(
...     servo=Servo(amplifier=Amplifier()),
...     controller=Controller(),
...     settings=Settings(environment="production"),
... )

>>> robot.work()

Dependency injection with dependencies

>>> from dependencies import Injector

>>> class Container(Injector):
...     robot = Robot
...     servo = Servo
...     amplifier = Amplifier
...     controller = Controller
...     settings = Settings
...     environment = "production"

>>> Container.robot.work()

Questions

If you have any questions, feel free to create an issue in our Task Tracker. We have the question label exactly for this purpose.

License

Dependencies library is offered under the two clause BSD license.

— ⭐️ —

The dependencies library is part of the SOLID python family.

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

dependencies-2.0.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

dependencies-2.0.1-py2.py3-none-any.whl (15.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file dependencies-2.0.1.tar.gz.

File metadata

  • Download URL: dependencies-2.0.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.3 Linux/4.15.0-1091-azure

File hashes

Hashes for dependencies-2.0.1.tar.gz
Algorithm Hash digest
SHA256 89f8262059ee6fb7a27f12bc72cec41e4a954a7b6f5ba0b4c902be1495e1cd12
MD5 7487c57864ca103ad70fdd722ef42f61
BLAKE2b-256 cbc88d296cc25e199183233f7eb79d8bd80598484491b7200d0a5407af285000

See more details on using hashes here.

File details

Details for the file dependencies-2.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: dependencies-2.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.9 CPython/3.8.3 Linux/4.15.0-1091-azure

File hashes

Hashes for dependencies-2.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4f2acdafd3f17f20b717e0691f5652d01bb1099f9d851926e7d2913bff299c61
MD5 ec8c171da34c7dc76b21db9d884b3b3c
BLAKE2b-256 a6b7d07e44c49429eba1c2eeffbde551a9ea3838c5ab34fafd544999fd4f925e

See more details on using hashes here.

Supported by

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