Pooling connections in Entity Framework Core 2.0
With the recent release of Entity Framework Core 2.0, we can pool connections by using the AddDbContextPool method in the Startup class. As we already know, in ASP.NET Core, we have to add the DbContext object using Dependency Injection (DI) in the ConfigureServices method in the Startup class, and when it is used in the controller, a new instance of the DbContext object is injected. To optimize performance, Microsoft has provided this AddDbContextPool method, which first checks for the available database context instance and injects it wherever it is needed. On the other hand, if the database context instance is not available, a new instance is created and injected.
The following code shows how AddDbContext can be added in the ConfigureServices method in the Startup class:
services.AddDbContextPool<SampleDbContext>( options => options.UseSqlServer(connectionString));