juniorDependency Injection
What is a DI Container (IoC Container)?
Updated Apr 28, 2026
Short answer
A DI Container is a framework that automates the instantiation of objects and the resolution of their dependencies.
Deep explanation
Instead of manually creating objects and passing them around (Pure DI), you register your interfaces and their concrete implementations with a container. When an object is requested, the container reflects on its constructor, resolves all required dependencies, builds them, and returns the fully constructed object.
Real-world example
Using frameworks like Spring (Java), ASP.NET Core DI (C#), or InversifyJS (Node) to manage application wiring automatically.
Common mistakes
- Treating the container as a global variable and passing it into classes (Service Locator anti-pattern).
Follow-up questions
- Do you strictly need a DI container to use DI?