Skip to content

Commit

Permalink
Cache root application service provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Dec 31, 2022
1 parent 13db9f1 commit f5b4966
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/EFCore/Infrastructure/CoreOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public virtual CoreOptionsExtension WithApplicationServiceProvider(IServiceProvi
var clone = Clone();

clone._applicationServiceProvider = applicationServiceProvider;
clone._rootApplicationServiceProvider ??= _autoResolveResolveRootProvider
? applicationServiceProvider?.GetService<ServiceProviderAccessor>()?.RootServiceProvider
: null;

return clone;
}
Expand Down Expand Up @@ -160,6 +163,9 @@ public virtual CoreOptionsExtension WithAutoResolveRootApplicationServiceProvide
var clone = Clone();

clone._autoResolveResolveRootProvider = autoResolve;
clone._rootApplicationServiceProvider ??= autoResolve
? _applicationServiceProvider?.GetService<ServiceProviderAccessor>()?.RootServiceProvider
: null;

return clone;
}
Expand Down Expand Up @@ -458,10 +464,7 @@ public virtual IServiceProvider? ApplicationServiceProvider
/// The option set from the <see cref="DbContextOptionsBuilder.UseRootApplicationServiceProvider" /> method.
/// </summary>
public virtual IServiceProvider? RootApplicationServiceProvider
=> _rootApplicationServiceProvider
?? (_autoResolveResolveRootProvider
? _applicationServiceProvider?.GetService<ServiceProviderAccessor>()?.RootServiceProvider
: null);
=> _rootApplicationServiceProvider;

/// <summary>
/// The option set from the <see cref="DbContextOptionsBuilder.UseRootApplicationServiceProvider" /> method.
Expand Down

0 comments on commit f5b4966

Please sign in to comment.