解决办法

由于底层类的构造函数依赖的是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

相关文章:

  • 2021-08-16
  • 2021-08-24
  • 2022-12-23
  • 2021-08-06
  • 2021-05-10
  • 2021-11-28
  • 2021-04-22
  • 2021-12-31
猜你喜欢
  • 2021-07-23
  • 2021-09-15
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案