I would like to execute migration in separate environments. I'm working with Entity Framework and ASP.NET Core. For now I have this :
public class TemporaryDbContextFactory : IDbContextFactory<ApplicationDbContext>
{
public ApplicationDbContext Create(DbContextFactoryOptions options)
{
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseSqlServer("Data Source=.\\LOCALHOST;Initial Catalog=MyDB;Integrated Security=True;MultipleActiveResultSets=true");
return new ApplicationDbContext(builder.Options);
}
}
This code is in a DAL class library who separate the database interactions from the server code.
It's ok to use this when executing migrations but I don't really like doing it like this.
The problem here is that I use a local database for development but we also have a development server and a staging server with different connection strings. What I can't manage to do is to find a way to not hardcode the connection strings in that class.
Is there a way to configure the connection strings for different environments and indicate which to use when executing the migrations ?