Enhance logging for "More than twenty 'IServiceProvider' instances warning" scenarios

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ajcvickerscommented, Aug 20, 2018

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.

1reaction
kieronlanningcommented, Aug 20, 2018

@ajcvickers @felixhayashi No Pomelo.EntityFrameworkCore.MySql here…

Mine was purely EF with MS SQL.

Read more comments on GitHub >

github_iconTop Results From Across the Web

than twenty 'IServiceProvider' instances have been created ...
After user successfully logs-in, The client application authorizes the user making sure user exists in the client application's database.
Read more >
DbContextOptionsBuilder.ConfigureWarnings Method
Configures the runtime behavior of warnings generated by Entity Framework. You can set a default behavior and behaviors for each warning type.
Read more >
"More than twenty 'IServiceProvider' instances" error with ...
After opening a connection to more than 20 schemas, we crash with the following error message: More than twenty 'IServiceProvider' instances ...
Read more >
Error Handling and ExceptionFilter Dependency Injection for ...
Exception handling in API applications is important as errors - both handled and unhandled - need to be passed to clients in some...
Read more >
Understanding Dependency Injection in .NET Core
Learn what Dependency Injection and IoC are and what .NET Core provides you to support them.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found