2 ms·
> 4) Dependency injection. Can you explain why DI needs an entire framework/libary? When I was taught DI in school, I was given the impression that DI was a $
by Sohcahtoa82 4y ago
> 4) Dependency injection.
Can you explain why DI needs an entire framework/libary?
When I was taught DI in school, I was given the impression that DI was a $1000 term for a $5 concept in that without DI, you write code like this:
class Foo(object):
def __init__(self):
self.bar = GetBar()
whereas with DI, you write this:
class Foo(object):
def __init__(self, bar):
self.bar = bar
Obviously, I'm grossly misunderstanding what DI is, because if that's really all it was, you wouldn't need a DI framework. I just haven't had to write code using any sort of DI more complicated than that.
- xboxnolifes 4y agoWhat you say is dependency injection, but what people usually mean when they say a "dependency injection framework" is the bits of managing the creation of dependencies and getting them into the class's scope without having to add it as a parameter to every upper scope class's argument list.
- Sohcahtoa82 4y agoAh... Do you know any good references for describing DI frameworks more? Because right now, my cynical take based on your description is that it's a TON of over-engineering and an absurd amount of complexity being added just to avoid a couple extra lines of code.