I'm attempting to use migrations EFCore2.0 in a .NET standard 2.0 class library, and so far I have something like
public class SomeContextFactory : IDesignTimeDbContextFactory<SomeContext>
{
private Configuration _configuration;
public SomeContextFactory(Configuration configuration)
{
_configuration = configuration;
}
public SomeContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<SomeContext>();
optionsBuilder.UseSqlServer(_configuration.ConnectionString);
return new SomeContext(optionsBuilder.Options);
}
}
public class SomeContext : DbContext
{
public DbSet<SomeDbModel> Some { get; set; }
public SomeContext(DbContextOptions<SomeContext> options) : base(options)
{
}
}
The point is that the connection string is different depending on the environment (dev,test,prod), and migrations should be performed on the database specified by the Configuration.
How do instruct migrations to inject Configuration into SomeContextFactory?