Skip to content

Commit

Permalink
Add Keyed services support in ShellScopeServices (OrchardCMS#14998)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored and urbanit committed Mar 18, 2024
1 parent d4234c4 commit de6ef32
Showing 1 changed file with 18 additions and 11 deletions.
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);
}

0 comments on commit de6ef32

Please sign in to comment.