diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/SimplePageToolbarContributor.cs b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/SimplePageToolbarContributor.cs index 647538c121..6e47281a70 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/SimplePageToolbarContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/SimplePageToolbarContributor.cs @@ -16,6 +16,8 @@ public class SimplePageToolbarContributor : IPageToolbarContributor public string? RequiredPolicyName { get; } + private bool? _shouldAddComponent; + public SimplePageToolbarContributor( Type componentType, Dictionary? arguments = null, @@ -38,15 +40,19 @@ public class SimplePageToolbarContributor : IPageToolbarContributor protected virtual async Task ShouldAddComponentAsync(PageToolbarContributionContext context) { - if (RequiredPolicyName != null) + if (_shouldAddComponent.HasValue) + { + return _shouldAddComponent.Value; + } + + if (RequiredPolicyName == null) { - var authorizationService = context.ServiceProvider.GetRequiredService(); - if (!await authorizationService.IsGrantedAsync(RequiredPolicyName)) - { - return false; - } + _shouldAddComponent = true; + return _shouldAddComponent.Value; } - return true; + var authorizationService = context.ServiceProvider.GetRequiredService(); + _shouldAddComponent = await authorizationService.IsGrantedAsync(RequiredPolicyName); + return _shouldAddComponent.Value; } }