3 ms·
I’ve used this exact pattern. However, in Python I prefer to use true DI. I mostly like Injector[0] because it’s lightweight and more like a set of primitives
by rybosome 1y ago
I’ve used this exact pattern.
However, in Python I prefer to use true DI. I mostly like Injector[0] because it’s lightweight and more like a set of primitives than an actual framework. Very easy to build functionality on top of and reuse - I have one set of modules that can be loaded for an API server, CLI, integration tests, offline workers, etc.
That said, I have a few problems with it - 2 features which I feel are bare minimum required, and one that isn’t there but could be powerful. You can’t provide async dependencies natively, which is not usable in 2025 - and it’s keyed purely on type, so if you want to return different string instances with some additional key you need a wrapper type.
Between these problems and missing features (Pydantic-like eval time validation of wiring graphs) I really want to write my own library.
However, as a testament to the flexibility of Injector, I could implement all 3 of these things as a layer on top without modifying its code directly.
[0]: https://pypi.org/project/injector/ https://pypi.org/project/injector/