Dependency Injection Pattern

Inject dependencies rather than creating them

Overview

Dependency Injection is a technique where an object receives other objects that it depends on. It implements Inversion of Control for resolving dependencies.

Code Example

java
1public class Service {
2    private Repository repo;
3    // INJECTED through constructor
4    public Service(Repository repo) { this.repo = repo; }
5}

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In
Dependency Injection Pattern - Additional Patterns | LLD | Revise Algo