I use Net Core 2.1 and I need to do some preparations on startup which require several direct Identity database queries.
I tried:
using (var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>() .CreateScope()) { var identityDb = serviceProvider.GetService<ApplicationDbContext>(); } these lines produce exception: Cannot resolve scoped service 'Ecoc.Data.ApplicationDbContext' from root provider. Is there a way to get database context in arbitrary place of code?