If you make this a static field in global.asax, you will run into concurrency issues. Multiple threads from multiple requests can arrive and receive each other. To make matters worse, this will not be displayed until you start getting more traffic on your website or until you start stress testing. You will implement it as a singleton, everything will work well in your testing, and you will think: "I am a genius! See how pure this implementation is!" But someday you will be burnt by it, just like me. The results will be confused, users will begin to see data that does not belong to them, and the site will behave unexpectedly.
The context classes for both the Entity Framework and LINQ to SQL were designed as the lightweight instance that you configured for each set of queries that you want to run. He did not have to live long.
Check out this other question / answer on stack overflow on the same topic, differently.
Dawson Toth Jan 31 2018-11-11T00: 00Z
source share