Use DbContext in ASP .Net Singleton Injected Class
问题 I need to access my database in a Singleton class instantiated in my Startup class. It seems that injecting it directly results in a DbContext that is disposed. I get the following error: Cannot access a disposed object. Object name: 'MyDbContext'. My question is twofold: Why doesn't this work and how can I access my database in a singleton class instance? Here is my ConfigureServices method in my Startup class: public void ConfigureServices(IServiceCollection services) { // code removed for