A singleton is created once and shared for the life of the application, so it must be thread safe. A scoped service is created once per scope, which in ASP.NET Core means once per request, and suits a DbContext. A transient is created every time it is requested. The classic bug is a captive dependency: a singleton holding a scoped service, which then lives far longer than intended and gets shared across requests.
Why interviewers ask this
Lifetimes look like trivia but cause real bugs, from a DbContext shared across threads to stale data and memory leaks. The interviewer wants clear definitions, examples of what belongs in each, and the captive dependency problem. Knowing that the container can validate scopes, and how a singleton or background service should create its own scope, shows you have fixed these problems rather than just read about them.
How to structure your answer
- Define each lifetime with a typical example.
- Explain the captive dependency problem.
- Mention scope validation and how to catch it early.
- Show how a singleton safely uses scoped services.
Example answer
Singleton means one instance for the whole application. That suits stateless or expensive things, like a configured client or an in memory cache, but it must be thread safe because every request shares it. Scoped means one instance per scope, and in ASP.NET Core each request gets a scope, so everything in that request shares the same instance. DbContext is the standard example, since you want one unit of work per request and it is not thread safe. Transient means a new instance every time something asks for it, which suits lightweight, stateless services. The bug I always look for is a captive dependency, where a singleton takes a scoped service in its constructor. That scoped instance is then trapped inside the singleton for the life of the app, so one DbContext ends up shared across concurrent requests and starts throwing errors. Scope validation in the container catches this in development. When a singleton or background service needs scoped services, I inject the scope factory and create a scope per unit of work.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- Why is DbContext registered as scoped by default?
- What happens to a transient service that implements IDisposable?
- How would you register a service that needs a different implementation per tenant?
Related .net developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions