Skip to content

Commit

Permalink
Don't store ApplicationServiceProvider in the service provider cache …
Browse files Browse the repository at this point in the history
…key.

Fixes #27169
  • Loading branch information
AndriySvyryd committed Jan 18, 2022
1 parent e7fa151 commit e680870
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/EFCore/Internal/ServiceProviderCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,26 @@ public virtual IServiceProvider GetOrAdd(IDbContextOptions options, bool provide

if (coreOptionsExtension?.ServiceProviderCachingEnabled == false)
{
return BuildServiceProvider(options, _configurations).ServiceProvider;
return BuildServiceProvider(options, (_configurations, options)).ServiceProvider;
}

return _configurations.GetOrAdd(options, BuildServiceProvider, _configurations).ServiceProvider;
var cacheKey = options;
var extension = options.FindExtension<CoreOptionsExtension>();
if (extension != null
&& extension.ApplicationServiceProvider != null)
{
cacheKey = ((DbContextOptions)options).WithExtension(extension.WithApplicationServiceProvider(null));
}

return _configurations.GetOrAdd(cacheKey, BuildServiceProvider, (_configurations, options)).ServiceProvider;

static (IServiceProvider ServiceProvider, IDictionary<string, string> DebugInfo) BuildServiceProvider(
IDbContextOptions options,
ConcurrentDictionary<IDbContextOptions, (IServiceProvider ServiceProvider, IDictionary<string, string> DebugInfo)>
configurations)
IDbContextOptions _,
(ConcurrentDictionary<IDbContextOptions, (IServiceProvider ServiceProvider, IDictionary<string, string> DebugInfo)>,
IDbContextOptions) arguments)
{
var (configurations, options) = arguments;

ValidateOptions(options);

var debugInfo = new Dictionary<string, string>();
Expand Down

0 comments on commit e680870

Please sign in to comment.