We have a case similar to you. What we did is use the implementationfactory overload of the IServiceCollection in the ConfigureServices method of the launch class, for example, like this:
services.AddTransient<ApplicationDbContextFactory>();
services.AddTransient(provider => provider.GetService<ApplicationDbContextFactory>().CreateApplicationDbContext());
CreateApplicationDbContext , , . , , , :
public ApplicationDbContext CreateApplicationDbContext(){
}
, ApplicationDbContext , :
public MyController(ApplicationDbContext dbContext)
{
_dbContext = dbContext;
}
:
public IActionResult([FromServices] ApplicationDbContext dbContext){
}
, , ApplicationDbContext , .
, .
№ 1 . , AddTransient AddDbContext, ... . .
.
... , " " ( , ) , .
, , , GitHub, , AddDbContext. ... . "" ( "") - , . , , AddDbContext, . , AddDbContext, .
, . AddDbContext EF . , ( , ). AddTransient - Asp.Net Core, . .
?