What are DI Lifetimes (Transient, Scoped, Singleton)?
Updated Apr 28, 2026
Short answer
Lifetimes dictate how long a DI container keeps an object instance alive before creating a new one.
Deep explanation
Transient: A new instance is created every single time it is requested. Scoped: A single instance is created once per request (e.g., HTTP request) and shared within that scope. Singleton: A single instance is created once for the entire lifespan of the application.
Real-world example
Singleton for a Configuration reader. Scoped for a Database Transaction per HTTP request. Transient for a lightweight data formatter.
Common mistakes
- Making a DbContext a Singleton, leading to data corruption and thread-safety exceptions across concurrent requests.
Follow-up questions
- Which lifetime is the safest default?