Entity Framework Core service default lifetime

asp.net-core entity-framework-core

Accepted Answer

ZZZ_tmp
60
11/20/2017 11:56:00 AM

Popular Answer

Note: A new technique has been added to EF Core 2.AddDbContextPool which develops a collection of reusable contexts. The instance will be "reset" and returned to the pool while the scoping remains the same. I suppose that isn't the case since I would have assumed that the overhead of "resetting" would be the same as just generating a new one.

If this method is used, at the time a DbContext instance is requested by a controller we will first check if there is an instance available in the pool. Once the request processing finalizes, any state on the instance is reset and the instance is itself returned to the pool.+

This is conceptually similar to how connection pooling operates in ADO.NET providers and has the advantage of saving some of the cost of initialization of DbContext instance.

https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-2.0#high-performance



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow