Implementation of dependency injection for Python 3
pip install rodiImplementation of dependency injection for Python 3
Features:
- types resolution by signature types annotations (type hints)
- types resolution by class annotations (type hints)
- types resolution by names and aliases (convention over configuration)
- unintrusive: builds objects graph without the need to change the source code of classes
- minimum overhead to obtain services, once the objects graph is built
- support for singletons, transient, and scoped services
This library is freely inspired by .NET Standard
Microsoft.Extensions.DependencyInjection implementation (ref. MSDN,
Dependency injection in ASP.NET
Core,
Using dependency injection in a .Net Core console
application).
The ContainerProtocol for v2 is inspired by punq.
Documentation
Rodi is documented here: https://www.neoteroi.dev/rodi/.
Installation
pip install rodi
Efficient
rodi works by inspecting code once at runtime, to generate
functions that return instances of desired types - as long as the object graph
is not altered. Inspections are done either on constructors
() or class annotations. Validation steps, for
example to detect circular dependencies or missing services, are done when
building these functions, so additional validation is not needed when
activating services.