Quick Answer
Transient: new instance created every time the service is requested รขโฌโ for lightweight, stateless services. Scoped: one instance per HTTP request รขโฌโ for DbContext and request-specific services. Singleton: one instance for the app lifetime รขโฌโ for caches, config wrappers, and truly shared services. Injecting a Scoped service into a Singleton causes a captive dependency bug.
Answer
ASP.NET Core's DI container supports three main lifetimes:
Transient โ A new instance is created every time it is requested. Best for lightweight, stateless services.
Scoped โ One instance per HTTP request. Ideal for services that work with per-request data such as unit-of-work or context services.
Singleton โ A single instance is created and shared for the lifetime of the application. Must be thread-safe and used carefully around shared state.
Choosing the wrong lifetime can lead to concurrency bugs, memory leaks, or stale data.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.
Complete .NET Core interview questions and answers covering beginner, junior, mid-level, senior, and expert concepts for freshers and experienced developers.