Thiru LogsAll FAQs
.NET & C# ยท ASP.NET Core

How would you solve an interview scenario involving dependency injection lifetimes?

AdvancedUpdated 2026-08-08

A BackgroundService is singleton but needs a DbContext. Inject IServiceScopeFactory, create a scope for each unit of work, and resolve the scoped DbContext from that scope.

#aspnet-core#dependency injection lifetimes