Base solution for your next web application
Open Closed

Resolve DbContext in WebModule PreInitialize #5218


User avatar
0
hitaspdotnet created

Dear support team
Hi,
I want run the EF runtime migration method by using MyPluginDbContext.Database.Migrate() command in PreInitialize method of MyPluginMvcWebModule if that migrate isn't applied before. But I can't resolve required services for that.
I'm trying to resolve DbContext with DbContextProvider and
IocManager.Resolve<IHttpContextAccessor>().HttpContext.RequestServices.GetRequiredService<CMSDbContext>();
Can you guide me please to resolve DbContext services in modules configuration? It's can be helpful for plugins with DbMigration.

Thanks.
Best regards.


5 Answer(s)