Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 2
    This will work, but wouldn't be a good idea, especially not in ASP.NET apps. Commented Aug 2, 2020 at 3:40
  • 4
    I know DBContext as Singleton is very bad idea, but in my case, i need to keep my service run even after the request is end due to long processing.. and since dbcontext will disposed after my request end, i tried to change its lifetime to singleton, and it works just what i expected. The question is, why it is so bad? and how do i access dbcontext after request end if not supposed to be singleton? Commented Nov 24, 2020 at 13:53
  • @hphp - Did this ever cause issues for you as I have EXCATLY the same scenario as you. I have a windows service with an endpoint which must return a response quickly while a background task writes a record to the DB. Commented Oct 9, 2024 at 8:56