Dependency Injection (DI) means an object receives its dependencies from the outside instead of creating them itself. It's a form of Inversion of Control (IoC): the responsibility for wiring objects is inverted away from the object and given to a caller or container.
Without DI vs. with DI
python
:
():
.repo = PostgresOrderRepo()
:
():
.repo = repo
service = OrderService(PostgresOrderRepo())
test = OrderService(InMemoryOrderRepo())
