Glossary term
What is dependency injection? Meaning for developers
In Backend in Depth
Give a function the things it needs (a repository, a clock) from outside. Do not let it import or create them itself.
Learn it properly · Backend in DepthLesson 0: Clean Code for Backends: Naming, Small Functions and BoundariesThe few clean-code rules that improve backend code reviews: pure domain logic, clear dependencies, no hidden I/O, and when not to add an abstraction.In Design Patterns & LLD
Pass an object's dependencies in from outside instead of creating them inside, so they can be swapped in tests.
Learn it properly · Design Patterns & LLDLesson 1: Creational Patterns: Factory, Builder, Singleton and FriendsFactories, builder, the module singleton and its traps, prototype, and dependency injection as the practical replacement.