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.