Skip to content

Commit

Permalink
Improve
Browse files Browse the repository at this point in the history
  • Loading branch information
realLiangshiwei committed Jan 29, 2024
1 parent d3058a9 commit 8d9e3e0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,28 @@ namespace Volo.Abp.Authorization.Permissions;

public class PermissionValueProviderManager : IPermissionValueProviderManager, ISingletonDependency
{
public IReadOnlyList<IPermissionValueProvider> ValueProviders => GetProviders();
public IReadOnlyList<IPermissionValueProvider> ValueProviders => _lazyProviders.Value;
private readonly Lazy<List<IPermissionValueProvider>> _lazyProviders;

protected AbpPermissionOptions Options { get; }
protected IServiceProvider ServiceProvider { get; }

public PermissionValueProviderManager(
IServiceProvider serviceProvider,
IOptions<AbpPermissionOptions> options)
{
Options = options.Value;
ServiceProvider = serviceProvider;

_lazyProviders = new Lazy<List<IPermissionValueProvider>>(
() => Options
.ValueProviders
.Select(c => serviceProvider.GetRequiredService(c) as IPermissionValueProvider)
.ToList()!,
true
);
_lazyProviders = new Lazy<List<IPermissionValueProvider>>(GetProviders, true);
}

protected virtual List<IPermissionValueProvider> GetProviders()
{
var providers = _lazyProviders.Value;
var providers = Options
.ValueProviders
.Select(type => (ServiceProvider.GetRequiredService(type) as IPermissionValueProvider)!)
.ToList();

var multipleProviders = providers.GroupBy(p => p.Name).FirstOrDefault(x => x.Count() > 1);
if(multipleProviders != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,28 @@ namespace Volo.Abp.Features;

public class FeatureValueProviderManager : IFeatureValueProviderManager, ISingletonDependency
{
public IReadOnlyList<IFeatureValueProvider> ValueProviders => GetProviders();
public IReadOnlyList<IFeatureValueProvider> ValueProviders => _lazyProviders.Value;
private readonly Lazy<List<IFeatureValueProvider>> _lazyProviders;

protected AbpFeatureOptions Options { get; }
protected IServiceProvider ServiceProvider { get; }

public FeatureValueProviderManager(
IServiceProvider serviceProvider,
IOptions<AbpFeatureOptions> options)
{
Options = options.Value;
ServiceProvider = serviceProvider;

_lazyProviders = new Lazy<List<IFeatureValueProvider>>(
() => Options
.ValueProviders
.Select(c => serviceProvider.GetRequiredService(c) as IFeatureValueProvider)
.ToList()!,
true
);
_lazyProviders = new Lazy<List<IFeatureValueProvider>>(GetProviders, true);
}

protected virtual List<IFeatureValueProvider> GetProviders()
{
var providers = _lazyProviders.Value;
var providers = Options
.ValueProviders
.Select(type => (ServiceProvider.GetRequiredService(type) as IFeatureValueProvider)!)
.ToList();

var multipleProviders = providers.GroupBy(p => p.Name).FirstOrDefault(x => x.Count() > 1);
if(multipleProviders != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ namespace Volo.Abp.Settings;

public class SettingValueProviderManager : ISettingValueProviderManager, ISingletonDependency
{
public List<ISettingValueProvider> Providers => GetProviders();
public List<ISettingValueProvider> Providers => _lazyProviders.Value;

protected AbpSettingOptions Options { get; }
protected IServiceProvider ServiceProvider { get; }
private readonly Lazy<List<ISettingValueProvider>> _lazyProviders;

public SettingValueProviderManager(
Expand All @@ -20,19 +21,17 @@ public SettingValueProviderManager(
{

Options = options.Value;
ServiceProvider = serviceProvider;

_lazyProviders = new Lazy<List<ISettingValueProvider>>(
() => Options
.ValueProviders
.Select(type => serviceProvider.GetRequiredService(type) as ISettingValueProvider)
.ToList()!,
true
);
_lazyProviders = new Lazy<List<ISettingValueProvider>>(GetProviders, true);
}

protected virtual List<ISettingValueProvider> GetProviders()
{
var providers = _lazyProviders.Value;
var providers = Options
.ValueProviders
.Select(type => (ServiceProvider.GetRequiredService(type) as ISettingValueProvider)!)
.ToList();

var multipleProviders = providers.GroupBy(p => p.Name).FirstOrDefault(x => x.Count() > 1);
if(multipleProviders != null)
Expand Down

0 comments on commit 8d9e3e0

Please sign in to comment.