Constructor injection designed with OOP in mind.
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.
- Provide composition instead of inheritance.
- Solves top-down architecture problems.
- Boilerplate-free object hierarchies.
- API entrypoints, admin panels, CLI commands are oneliners.
Dependency injection without
>>> 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
>>> from dependencies import Injector >>> class Container(Injector): ... robot = Robot ... servo = Servo ... amplifier = Amplifier ... controller = Controller ... settings = Settings ... environment = "production" >>> Container.robot.work()
If you have an issue with any version of the library, you can apply for a paid enterprise support contract. This will guarantee you that no breaking changes will happen to you. No matter how old version you're using at the moment. All necessary features and bug fixes will be backported in a way that serves your needs.
Please contact email@example.com if you're interested in it.
dependencies library is offered under the two clause BSD license.
dependencies library is part of the SOLID python family.