Refactored.

pull/208/head
Halil İbrahim Kalkan 7 years ago
parent 94af238b95
commit 8f63f96ff2

@ -12,7 +12,8 @@ namespace Volo.Abp.Permissions
{
protected IPermissionDefinitionManager PermissionDefinitionManager { get; }
protected Lazy<List<IPermissionValueProvider>> Providers { get; }
protected List<IPermissionValueProvider> Providers => _lazyProviders.Value;
private readonly Lazy<List<IPermissionValueProvider>> _lazyProviders;
protected PermissionOptions Options { get; }
@ -24,7 +25,7 @@ namespace Volo.Abp.Permissions
PermissionDefinitionManager = permissionDefinitionManager;
Options = options.Value;
Providers = new Lazy<List<IPermissionValueProvider>>(
_lazyProviders = new Lazy<List<IPermissionValueProvider>>(
() => Options
.ValueProviders
.Select(c => serviceProvider.GetRequiredService(c) as IPermissionValueProvider)
@ -33,11 +34,11 @@ namespace Volo.Abp.Permissions
);
}
public async Task<bool> IsGrantedAsync(string name)
public virtual async Task<bool> 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<PermissionGrantInfo> GetPermissionGrantInfo(PermissionDefinition permission)
protected virtual async Task<PermissionGrantInfo> GetPermissionGrantInfo(PermissionDefinition permission)
{
foreach (var provider in Providers.Value)
foreach (var provider in Providers)
{
if (await provider.IsGrantedAsync(permission))
{

@ -10,9 +10,11 @@ namespace Volo.Abp.Permissions
{
public class PermissionDefinitionManager : IPermissionDefinitionManager, ISingletonDependency
{
protected Lazy<List<IPermissionDefinitionProvider>> Providers { get; }
protected List<IPermissionDefinitionProvider> Providers => _lazyProviders.Value;
private readonly Lazy<List<IPermissionDefinitionProvider>> _lazyProviders;
protected Lazy<IDictionary<string, PermissionDefinition>> PermissionDefinitions { get; }
protected IDictionary<string, PermissionDefinition> PermissionDefinitions => _lazyPermissionDefinitions.Value;
private readonly Lazy<IDictionary<string, PermissionDefinition>> _lazyPermissionDefinitions;
protected PermissionOptions Options { get; }
@ -25,8 +27,8 @@ namespace Volo.Abp.Permissions
_serviceProvider = serviceProvider;
Options = options.Value;
Providers = new Lazy<List<IPermissionDefinitionProvider>>(CreatePermissionProviders, true);
PermissionDefinitions = new Lazy<IDictionary<string, PermissionDefinition>>(CreatePermissionDefinitions, true);
_lazyProviders = new Lazy<List<IPermissionDefinitionProvider>>(CreatePermissionProviders, true);
_lazyPermissionDefinitions = new Lazy<IDictionary<string, PermissionDefinition>>(CreatePermissionDefinitions, true);
}
public virtual PermissionDefinition Get(string name)
@ -45,12 +47,12 @@ namespace Volo.Abp.Permissions
public virtual IReadOnlyList<PermissionDefinition> 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<IPermissionDefinitionProvider> CreatePermissionProviders()
@ -65,7 +67,7 @@ namespace Volo.Abp.Permissions
{
var permissions = new Dictionary<string, PermissionDefinition>();
foreach (var provider in Providers.Value)
foreach (var provider in Providers)
{
provider.Define(new PermissionDefinitionContext(permissions));
}

Loading…
Cancel
Save