3 ms·
I still miss dependency injection in Python
by throwaway7783 10mo ago
I still miss dependency injection in Python
- EdwardDiego 9mo agoFastAPI rolled their own using annotations. It's... ...okay.
- supriyo-biswas 9mo agoUnfortunately it also constructs dependencies per request instead of singletons, so you have to rely on hacks like `@lru_cache(maxsize=1)` on the factory functions. I'd really like to see a Python framework that embraces class-based controllers to do away with this problem; beyond that writing a dependency injection system is not too difficult of a task (the last time I did it for a hobby project many years ago, it was around ~150 lines of code).