3 ms·
DI is Dependency Injection, which is a $1,000 term for a $5 concept. A Python class without DI: class SomeClass(object): def __init__(self):
by Sohcahtoa82 9y ago
DI is Dependency Injection, which is a $1,000 term for a $5 concept.
A Python class without DI:
class SomeClass(object):
def __init__(self):
self.someDependency = GetDependency()
A Python class WITH DI:
class SomeClass(object):
def __init__(self, dependency):
self.someDependency = dependency
...
That's it. DI is just explicitly passing ("injecting") a dependent object into an object, rather than requiring the object to call a function to get a reference/pointer to the dependency or make one.