I am using ASP.Net Core 2.1
with EF Core 2.1
While running any Migration from PMC, I am getting the below error
Value cannot be null. Parameter name: connectionString
This is how my Context class looks like
public class MyAppContextFactory : IDesignTimeDbContextFactory<MyAppContext>
{
private readonly string _dbConnection;
public MyAppContextFactory()
{
}
public MyAppContextFactory(string dbConnection)
: this()
{
_dbConnection = dbConnection;
}
public MyAppContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<MyAppContext>();
optionsBuilder.UseSqlServer(_dbConnection, opts => opts.CommandTimeout((int)TimeSpan.FromMinutes(15).TotalSeconds));
return new MyAppContext(optionsBuilder.Options);
}
}
My Connection string is present in API layer in appsettings.json & as good practice I should not add any reference to EF in API/UI layer.
How do I set the connection string as per environment in such layered architecture?
Thanks.