.NET Core 3.1, EF Core 5.0 preview 6.
I am using Simple Injector 5.0 to register IMyContextFactory (I'm not using services.AddDbContext<>()).
My MyContext have all constructors set to private because I use ContextFactory without tenantId and sometimes with few different tenantIds at one request, so I make sure that everyone will use IMyContextFactory injection instead of MyContext and to prevent creating new MyContext() in controllers etc.
But how to do Update-Database?
- While I do
Update-DatabaseI always have errorLogin failed for user ''., but I can run and connect to database from my WebAPI project without any problem (my ConnectionString is good). - I was able to apply migration at runtime, but I have to add
services.AddDbContext<MyContext>(), make constructors forMyContextas public and get this context fromscope.ServiceProvider.GetRequiredService<MyContext>()in Program.cs, because myIMyContextFactorywas not insideServiceProvider. (via https://docs.microsoft.com/pl-pl/ef/core/managing-schemas/migrations/applying?tabs=vs#apply-migrations-at-runtime)
How to achieve that only with Simple Injector?