-3

when i register other services it work like services.AddSingleton<GeneratingData, GeneratingData>() but when i add services.AddSingleton<ApplicationDbContext, ApplicationDbContext>(); it does work this error shows up

enter image description here this is the code i write in startup file adding ApplicationDbContext for dependency injection

Zubair Khakwani
  • 328
  • 5
  • 18
  • 1
    Screenshots of code or error messages aren't accepted here. Please edit the code and messages into your question. – Ian Kemp Feb 05 '20 at 13:40
  • Welcome to Stack Overflow. Read the [tour] and [ask]. Start by reading the error message and researching it. – CodeCaster Feb 05 '20 at 13:50

1 Answers1

0

You are trying to inject a scoped service (ApplicationDbContext) in a singleton, that is not allowed since it will basically be captured as a singleton. If you want to use the DbContext, you will need to register the class that are going to use it as Scoped or Transient instead of Singleton

JOSEFtw
  • 9,781
  • 9
  • 49
  • 67