© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
Search
Star
Feedback
Setup for Free
C
C#
•
13mo ago
•
9 replies
Core
✅ Proper way of using EF DbContext in a BackgroundService
Hello
,
The dbContext and the
BackgroundService
BackgroundService
have different scopes
. I
've seen there are 2 solutions
.
The possible options are
: injecting the
IServiceProvider
IServiceProvider
, or the
IServiceScopeFactory
IServiceScopeFactory
, then manually creating a context
.
Which one of the interfaces is better to use
? There surely must be some difference
.
.
.
C#
Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Similar Threads
Was this page helpful?
Yes
No
Recent Announcements
Similar Threads
✅ EF Core, Proper DbContext Instantiation
C
C# / help
3y ago
BackgroundService and dbcontext memory issue
C
C# / help
2y ago
Proper usage of EF Core in teams?
C
C# / help
15mo ago
What are exactly DbContext and DbSet in EF? [Answered]
C
C# / help
4y ago