Skip to main content

Explain DI lifetimes: Transient, Scoped, Singleton.

Senior .NET Core
Quick Answer Transient: fresh instance each injection รขโ‚ฌโ€ good for lightweight, stateless services. Scoped: single instance per HTTP request รขโ‚ฌโ€ EF Core DbContext is the classic example. Singleton: one shared instance for the app's lifetime รขโ‚ฌโ€ should be thread-safe. Never capture Scoped or Transient services in a Singleton รขโ‚ฌโ€ they'll be shared across all requests incorrectly.

Answer

Transient: New instance each request.
Scoped: One instance per HTTP request.
Singleton: One instance for entire app lifetime.

Wrong lifetimes cause concurrency bugs, memory leaks, or stale state.

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.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice