© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#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# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ EF Core, Proper DbContext Instantiation
C#CC# / help
3y ago
BackgroundService and dbcontext memory issue
C#CC# / help
2y ago
Proper usage of EF Core in teams?
C#CC# / help
15mo ago
What are exactly DbContext and DbSet in EF? [Answered]
C#CC# / help
4y ago