Re:Minimalist dependency injection in Python (2021)
by ivanche on Thursday April 14, 2022 @03:27AM
(#31024250)
Thank you for very detailed reply! As the matter of fact, I mostly agree with you and prefer such a direct (or manually wired) approach to DI, over Spring's declarative one. Somehow I was under impression that you are against DI as a concept. I am sorry for that.
My original reply was in response to "please don't make Python Java", where that flavor of spooky action DI seems to be common.
To your original question: `what do I suggest`. I point to the authors example:
My suggestion: please not that.How about:
As someone who's been writing python for a while, I could walk into this having never read it before and say...ok sure, when prod, B takes A behavior, but when not prod, B takes C behavior.In the proposed example, I would go in, read it (assuming I know to even look for this non-idiomatic use of the language) and then read through this code to figure out what should have just been an argument passed to B.
Which leads back to my original question: what is this buying me over dunder main or handing some arguments? In terms of cost, I have to understand something and walk through the code to understand something that could have been done more simply and more explicitly without this DI pattern.
Edit: formatting