-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support resolving application services from singleton internal services
Fixes #13540 Scoped and transient internal services can obtain application services using the `DbContext` as a service locator. Singleton services cannot do this since they do not have access to the `DbContext`. This change allows the root application service provider to be registered as an `ISingletonOption` such that singleton internal services can resolve singleton and transient application services.
- Loading branch information
1 parent
32552c6
commit 13db9f1
Showing
8 changed files
with
380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.EntityFrameworkCore.Infrastructure; | ||
|
||
/// <summary> | ||
/// This type is added as a singleton service to the application service provider to provide access to the | ||
/// root service provider. | ||
/// </summary> | ||
public class ServiceProviderAccessor | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ServiceProviderAccessor" /> class. | ||
/// </summary> | ||
/// <param name="rootServiceProvider">The injected service provider.</param> | ||
public ServiceProviderAccessor(IServiceProvider rootServiceProvider) | ||
{ | ||
RootServiceProvider = rootServiceProvider; | ||
} | ||
|
||
/// <summary> | ||
/// The injected service provider. | ||
/// </summary> | ||
public virtual IServiceProvider RootServiceProvider { get; } | ||
} |
Oops, something went wrong.