I'm trying to work with several databases in which have the same schema structure with my .NET Core 2.2 Web application (with Dependency Injection approach + Entity Framework). I want to allow user can choose (or change) the database at runtime. so I have 2 questions.
1. Is it possible to change DbContext
during the runtime?
2. Is it possible to configure(Dependency Injection) DbContext
after launching the application?
If so, How?
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
...
services.AddDbContext<MyDbContext>(option => option.UseMySql(Configuration.GetConnectionString("DevConnection")));
// Can I declare this after launching the app? or Can it be changed at Runtime?
...