forked from OrchardCMS/OrchardCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Keyed services support in ShellScopeServices (OrchardCMS#14998)
- Loading branch information
1 parent
d4234c4
commit de6ef32
Showing
1 changed file
with
18 additions
and
11 deletions.
There are no files selected for viewing
29 changes: 18 additions & 11 deletions
29
src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeServices.cs
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 |
---|---|---|
@@ -1,18 +1,25 @@ | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using OrchardCore.Environment.Shell.Builders; | ||
|
||
namespace OrchardCore.Environment.Shell.Scope | ||
namespace OrchardCore.Environment.Shell.Scope; | ||
|
||
/// <summary> | ||
/// Makes an 'IServiceProvider' aware of the current 'ShellScope'. | ||
/// </summary> | ||
public class ShellScopeServices(IServiceProvider services) : IKeyedServiceProvider | ||
{ | ||
public class ShellScopeServices : IServiceProvider | ||
{ | ||
private readonly IServiceProvider _services; | ||
private readonly IServiceProvider _services = services; | ||
|
||
private IServiceProvider Services | ||
=> ShellScope.Services ?? _services; | ||
|
||
/// <summary> | ||
/// Makes an 'IServiceProvider' aware of the current 'ShellScope'. | ||
/// </summary> | ||
public ShellScopeServices(IServiceProvider services) => _services = services; | ||
public object GetKeyedService(Type serviceType, object serviceKey) | ||
=> Services.GetKeyedService(serviceType, serviceKey); | ||
|
||
private IServiceProvider Services => ShellScope.Services ?? _services; | ||
public object GetRequiredKeyedService(Type serviceType, object serviceKey) | ||
=> Services.GetRequiredKeyedService(serviceType, serviceKey); | ||
|
||
public object GetService(Type serviceType) => Services?.GetService(serviceType); | ||
} | ||
public object GetService(Type serviceType) | ||
=> Services?.GetService(serviceType); | ||
} |