From 8f63f96ff28595cf5fc7e7eaebe1da2fd4fb75ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 13 Feb 2018 09:07:03 +0300 Subject: [PATCH] Refactored. --- .../Volo/Abp/Permissions/PermissionChecker.cs | 13 +++++++------ .../Permissions/PermissionDefinitionManager.cs | 16 +++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionChecker.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionChecker.cs index cc1ac7496a..e696b10ba8 100644 --- a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionChecker.cs +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionChecker.cs @@ -12,7 +12,8 @@ namespace Volo.Abp.Permissions { protected IPermissionDefinitionManager PermissionDefinitionManager { get; } - protected Lazy> Providers { get; } + protected List Providers => _lazyProviders.Value; + private readonly Lazy> _lazyProviders; protected PermissionOptions Options { get; } @@ -24,7 +25,7 @@ namespace Volo.Abp.Permissions PermissionDefinitionManager = permissionDefinitionManager; Options = options.Value; - Providers = new Lazy>( + _lazyProviders = new Lazy>( () => Options .ValueProviders .Select(c => serviceProvider.GetRequiredService(c) as IPermissionValueProvider) @@ -33,11 +34,11 @@ namespace Volo.Abp.Permissions ); } - public async Task IsGrantedAsync(string name) + public virtual async Task IsGrantedAsync(string name) { var permission = PermissionDefinitionManager.Get(name); - foreach (var provider in Providers.Value) + foreach (var provider in Providers) { if (await provider.IsGrantedAsync(permission)) { @@ -61,9 +62,9 @@ namespace Volo.Abp.Permissions return permissionGrantInfos.Values.ToList(); } - private async Task GetPermissionGrantInfo(PermissionDefinition permission) + protected virtual async Task GetPermissionGrantInfo(PermissionDefinition permission) { - foreach (var provider in Providers.Value) + foreach (var provider in Providers) { if (await provider.IsGrantedAsync(permission)) { diff --git a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionDefinitionManager.cs b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionDefinitionManager.cs index 6e2f437649..e2644e28db 100644 --- a/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionDefinitionManager.cs +++ b/src/Volo.Abp.Permissions/Volo/Abp/Permissions/PermissionDefinitionManager.cs @@ -10,9 +10,11 @@ namespace Volo.Abp.Permissions { public class PermissionDefinitionManager : IPermissionDefinitionManager, ISingletonDependency { - protected Lazy> Providers { get; } + protected List Providers => _lazyProviders.Value; + private readonly Lazy> _lazyProviders; - protected Lazy> PermissionDefinitions { get; } + protected IDictionary PermissionDefinitions => _lazyPermissionDefinitions.Value; + private readonly Lazy> _lazyPermissionDefinitions; protected PermissionOptions Options { get; } @@ -25,8 +27,8 @@ namespace Volo.Abp.Permissions _serviceProvider = serviceProvider; Options = options.Value; - Providers = new Lazy>(CreatePermissionProviders, true); - PermissionDefinitions = new Lazy>(CreatePermissionDefinitions, true); + _lazyProviders = new Lazy>(CreatePermissionProviders, true); + _lazyPermissionDefinitions = new Lazy>(CreatePermissionDefinitions, true); } public virtual PermissionDefinition Get(string name) @@ -45,12 +47,12 @@ namespace Volo.Abp.Permissions public virtual IReadOnlyList GetAll() { - return PermissionDefinitions.Value.Values.ToImmutableList(); + return PermissionDefinitions.Values.ToImmutableList(); } public virtual PermissionDefinition GetOrNull(string name) { - return PermissionDefinitions.Value.GetOrDefault(name); + return PermissionDefinitions.GetOrDefault(name); } protected virtual List CreatePermissionProviders() @@ -65,7 +67,7 @@ namespace Volo.Abp.Permissions { var permissions = new Dictionary(); - foreach (var provider in Providers.Value) + foreach (var provider in Providers) { provider.Define(new PermissionDefinitionContext(permissions)); }