What are the advantages and disadvantages of creating a global entities context for the application (i.e. one static instance)?

Technology CommunityCategory: Entity FrameworkWhat are the advantages and disadvantages of creating a global entities context for the application (i.e. one static instance)?
VietMX Staff asked 3 years ago

Never ever use global context. Create a new ObjectContext instance in a Using statement for each service method so that it is disposed of before the method returns. This step is critical for scalability of your service. It makes sure that database connections are not kept open across service calls and that temporary state used by a particular operation is garbage collected when that operation is over. The Entity Framework automatically caches metadata and other information it needs in the app domain, and ADO.NET pools database connections, so re-creating the context each time is a quick operation.