Created
October 18, 2019 17:41
-
-
Save hd9/3de1da988890df442e2e451d57f0d25b to your computer and use it in GitHub Desktop.
Accessing Entity Framework context on the background on .NET Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 1 - Inject IServiceScopeFactory in your controller | |
// Source: https://blog.hildenco.com/2018/12/accessing-entity-framework-context-on.html | |
private readonly IServiceScopeFactory serviceScopeFactory; | |
public ApiController(ApplicationDbContext context, IServiceScopeFactory serviceScopeFactory) | |
{ | |
this.context = context; | |
this.serviceScopeFactory = serviceScopeFactory; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment