Is it possible to create a DbContext Interface or abstract class and use it to inject different DbContext Objects?
No, there isn't. But you can always build one like this:
interface IDbContext : IDisposable
{
DbSet<TEntity> Set<TEntity>() where TEntity : class;
Task<int> SaveChangesAsync();
}
public class MyDbContext : DbContext, IDbContext
{
public MyDbContext()
: base("myConnectionString")
{ }
//implementation
}
And inject IDbContext
when needed.