解决办法
由于底层类的构造函数依赖的是DbContext类,注入的是MyDbContext类,所以无法解析DbContext.需多加一行下面红色的代码
// 注册DbContext
services.AddDbContext<MyDbContext>(options => options.UseDm(Configuration.GetConnectionString("TestDMDB")));
services.AddScoped<DbContext, MyDbContext>(); //表明MyDbContext是DbContext的具体实现
详解:
https://stackoverflow.com/questions/46320189/asp-net-core-2-unable-to-resolve-service-for-type-microsoft-entityframeworkcore