我应该如何将DbContext实例注入(inject)(使用.NETCore的内置依赖注入(inject)库MS.DI)到单例中?在我的特定情况下,单例是IHostedService?我尝试了什么目前,我的IHostedService类在构造函数中采用了一个MainContext(派生自DbContext)实例。当我运行应用程序时,我得到:Cannotconsumescopedservice'Microsoft.EntityFrameworkCore.DbContextOptions'fromsingleton'Microsoft.Extensions.Hosting.IHostedS