Skip to content

Instantly share code, notes, and snippets.

@Orbis25
Created April 15, 2021 19:42
Show Gist options
  • Save Orbis25/f15b727f9b7eedb6f0dce463b10522bd to your computer and use it in GitHub Desktop.
Save Orbis25/f15b727f9b7eedb6f0dce463b10522bd to your computer and use it in GitHub Desktop.
get dbcontext instance in middleware
//IApplicationBuilder app;
using var appScoped = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope();
ApplicationDbContext _context = appScoped.ServiceProvider.GetService<ApplicationDbContext>();
UserManager<ApplicationUser> _userManager = appScoped.ServiceProvider.GetService<UserManager<ApplicationUser>>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment