Skip to content

Instantly share code, notes, and snippets.

@hd9
Created October 18, 2019 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hd9/3de1da988890df442e2e451d57f0d25b to your computer and use it in GitHub Desktop.
Save hd9/3de1da988890df442e2e451d57f0d25b to your computer and use it in GitHub Desktop.
Accessing Entity Framework context on the background on .NET Core
// 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