From 0f9eb3add489122eae2add60b9eb9192c3325e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 2 Nov 2020 17:44:39 +0300 Subject: [PATCH] AbpComponentBase should use non-scoped services for message and notification --- .../AspNetCore/Components/AbpComponentBase.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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)