Using ASP.NET MVC with .NET Core 2.2.
I have several similar databases and have a hierarchy of DbContext such as:
public class BaseContext : DbContext {}
public class DerivedContext : BaseContext {}
I have services and controllers that should work with both DbContext:
public class MyService
{
public MyService(BaseContext dbContext) {}
}
public class MyController : ControllerBase
{
public MyController (BaseContext dbContext) {}
}
I'm trying to use these with the derived database as follows:
services.AddDbContext<DerivedContext>(x => ...);
The problem is the dependency injector is unable to resolve the BaseContext parameters. How can I register the derived type with the dependency injection container and have it provided when the base type is requested?