Category: Software Engineering | Subcategory: Design Patterns
Last Updated: 2026-05-16
What This Cheat Sheet Covers
This topic spans 15 focused tables and 150 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Overview
Dependency Injection (DI) is a design pattern and software engineering technique that implements Inversion of Control (IoC) for resolving dependencies. DI allows objects to receive their dependencies from external sources rather than creating them internally, promoting loose coupling, testability, and maintainability in software systems.
Table 1: Core DI Concepts
Before reaching for a container or an annotation, it helps to nail down the vocabulary everyone uses loosely. These are the building blocks — what a dependency actually is, where it gets wired (the composition root), why we favor loose coupling over new, and how registration and resolution turn abstractions into running objects.
| Concept | Example | Description |
|---|---|---|
Dependency Injection | Service receives database connection via constructor instead of creating it | Pattern where dependencies are provided to a class from external sources rather than being created internally |
Inversion of Control (IoC) | Framework manages object instantiation and disposal instead of manual new/delete | Principle where control of object creation and lifecycle is transferred from the application to a framework/container |
Service Locator | ServiceLocator.Get<ILogger>() vs constructor injection | Anti-pattern where a centralized registry provides dependencies on demand (discouraged vs DI) |
Composition Root | Main() method or Startup.cs where DI container is configured | Single location in application where object graphs are assembled and dependencies wired together |
DI Container | Spring ApplicationContext, .NET IServiceProvider, NestJS Module system | Framework that manages dependency resolution, object creation, and lifecycle management |