SeniorSenior (6–10 yrs)C#.NETMicrosoftOracle
Scoped vs Singleton DI
What goes wrong if a Singleton service depends on a Scoped DbContext?
Answers use simple, clear English.
Quick interview answer
You get a captive dependency: the Scoped DbContext lives as long as the Singleton, causing stale data, threading issues, and disposed-context errors. Fix by injecting IServiceScopeFactory and creating scopes, or redesign lifetimes so Scoped depends on Singleton—not the reverse.
Detailed answer
You get a captive dependency: the Scoped DbContext lives as long as the Singleton, causing stale data, threading issues, and disposed-context errors. Fix by injecting IServiceScopeFactory and creating scopes, or redesign lifetimes so Scoped depends on Singleton—not the reverse.
seniortech-lead#di#efcore