2 ms·
Can you clarify what you mean by dependency injection in python? Did you mean a DI framework or something more informal? I've seen DI frameworks in python but
by np_tedious 6y ago
Can you clarify what you mean by dependency injection in python? Did you mean a DI framework or something more informal?
I've seen DI frameworks in python but not really used them. At a glance they don't strike me as pythonic. Rolling your own kind of inversion of control can result in unruly "config" or "context" objects that bring difficulties as well.
- oweiler 6y agoPass the fully constructed object as parameter. No need for a DI framework.
- idclip 6y agoI must say i havnt done any dependency injection in python. Did so in scala and JS though. So i assume he means initilize it once in program entry and Pass in the pointer to the object that needs it via including it the constructor or a function call. Do you think There’s a pythonic way of doing these things?
- fulafel 6y agoDI is just a convoluted synonym for passing in arguments.
- alexchamberlain 6y agoIndeed. If you want it to be cleaner, a discipline of constructor arguments for injection and __call__ arguments for semantic input is really all you need.