0

I read in some places that it would be good to use a singleton context, but what if it was in a service? It will keep running all the time, making from time to time requests to a REST API, so I'm thinking, it will have an instance of the DbContext allocated on the memory.

What would be better, the using (var context = new DbContext()) or a singleton DbContext?

1 Answers1

2

DbContext is cheap, and there is some housekeeping that occurs when they are created and disposed. Don't use a singleton for one.

d219
  • 2,707
  • 5
  • 31
  • 36