It used to be possible to change a context's connection string, after it was created.
I can't figure out how to do that with EF Core (and SQLite). I'm registering the context in the usual way, using the ASP.NET Core builtin IoC container.
services.AddDbContext<MyContext>(options =>
options.UseSqlite(cfg.GetConnectionString("DefaultConnection")));
I can't change the MyContext
class, as it's in a separate assembly which is the responsibility of someone else. So I can't change the constructor, OnConfiguring()
, etc.
So I need to re-create/init the container's current instance, using a new connection string.
Is there a way to do this?