C#C
C#11mo ago
Core

✅ Proper way of using EF DbContext in a BackgroundService

Hello,
The dbContext and the BackgroundService have different scopes. I've seen there are 2 solutions.
The possible options are: injecting the IServiceProvider, or the IServiceScopeFactory, then manually creating a context.
Which one of the interfaces is better to use? There surely must be some difference...
Was this page helpful?