Enhance logging for "More than twenty 'IServiceProvider' instances warning" scenarios
See original GitHub issueWhen using EF Core 2.1.1 after a number of calls into my service I start seeing the following warning:
More than twenty ‘IServiceProvider’ instances have been created for internal use by Entity Framework. This is commonly caused by injection of a new singleton service instance into every DbContext instance. For example, calling UseLoggerFactory passing in a new instance each time–see https://go.microsoft.com/fwlink/?linkid=869049 for more details. Consider reviewing calls on ‘DbContextOptionsBuilder’ that may require new service providers to be built.
I’ve followed the instructions details in the link in the warning, and from Issue #10235 but still the warning occurs.
The contexts all use the same ILoggerFactory by using the UseLoggerFactory extension:
services.AddDbContext<ApplicationDbContext>(
builder =>
{
builder
.UseLoggerFactory(LoggerFactory) // <-- Passed in during App class start-up in the constructor.
.UseSqlServer(defaultSqlConnectionString, options => options.MigrationsAssembly(migrationsAssembly));
});
EF Core version: 2.1.1 Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:21 (7 by maintainers)
Top Related StackOverflow Question
Triage: we will enhance the logging here for 2.2, and do it soon so that nightly builds and 2.2 previews will be able to use it to help debugging.
@ajcvickers @felixhayashi No
Pomelo.EntityFrameworkCore.MySqlhere…Mine was purely EF with MS SQL.