diff --git a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs index b2ed4e5603..006cc955fd 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components/Volo/Abp/AspNetCore/Components/AbpComponentBase.cs @@ -54,10 +54,10 @@ namespace Volo.Abp.AspNetCore.Components protected ICurrentUser CurrentUser => LazyGetRequiredService(ref _currentUser); private ICurrentUser _currentUser; - protected IUiMessageService Message => LazyGetRequiredService(ref _message); + protected IUiMessageService Message => LazyGetNonScopedRequiredService(ref _message); private IUiMessageService _message; - protected IUiNotificationService Notify => LazyGetRequiredService(ref _notify); + protected IUiNotificationService Notify => LazyGetNonScopedRequiredService(ref _notify); private IUiNotificationService _notify; protected IObjectMapper ObjectMapper @@ -97,6 +97,21 @@ namespace Volo.Abp.AspNetCore.Components return reference; } + protected TService LazyGetNonScopedRequiredService(ref TService reference) => LazyGetNonScopedRequiredService(typeof(TService), ref reference); + + protected TRef LazyGetNonScopedRequiredService(Type serviceType, ref TRef reference) + { + if (reference == null) + { + reference = (TRef)NonScopedServices.GetRequiredService(serviceType); + } + + return reference; + } + + [Inject] + protected IServiceProvider NonScopedServices { get; set; } + protected virtual IStringLocalizer CreateLocalizer() { if (LocalizationResource != null)