Back to course

Dependency Injection Basics

.NET Zero to Hero: Master C# and Modern App Development

Dependency Injection (DI)

DI is a design pattern that allows us to develop loosely coupled code. Instead of creating an object inside a class, we "inject" it.

Lifetime cycles in .NET:

  • Transient: Created every time they are requested.
  • Scoped: Created once per client request (e.g., web request).
  • Singleton: Created once and shared everywhere.