diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ApplicationConfigurationCache.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ApplicationConfigurationCache.cs new file mode 100644 index 0000000000..df41c996b6 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ApplicationConfigurationCache.cs @@ -0,0 +1,20 @@ +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Components.WebAssembly +{ + public class ApplicationConfigurationCache : ISingletonDependency + { + protected ApplicationConfigurationDto Configuration { get; set; } + + public virtual ApplicationConfigurationDto Get() + { + return Configuration; + } + + internal void Set(ApplicationConfigurationDto configuration) + { + Configuration = configuration; + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs index ab9b18f812..e403a8cfe9 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCachedApplicationConfigurationClient.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using Microsoft.Extensions.Caching.Memory; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.AspNetCore.Mvc.Client; using Volo.Abp.DependencyInjection; @@ -11,43 +10,41 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly { protected IHttpClientProxy Proxy { get; } - protected IMemoryCache Cache { get; } + protected ApplicationConfigurationCache Cache { get; } public WebAssemblyCachedApplicationConfigurationClient( IHttpClientProxy proxy, - IMemoryCache cache) + ApplicationConfigurationCache cache) { Proxy = proxy; Cache = cache; } - public async Task InitializeAsync() + public virtual async Task InitializeAsync() { - await GetAsync(); + Cache.Set(await Proxy.Service.GetAsync()); } - public async Task GetAsync() + public virtual Task GetAsync() { - return await Cache.GetOrCreateAsync( - CreateCacheKey(), - e => Proxy.Service.GetAsync() - ); + return Task.FromResult(GetConfigurationByChecking()); } - public ApplicationConfigurationDto Get() + public virtual ApplicationConfigurationDto Get() { - var cacheKey = CreateCacheKey(); - if(Cache.TryGetValue(cacheKey, out ApplicationConfigurationDto value)) - { - return value; - } - - throw new AbpException($"Should initialize the {nameof(ICachedApplicationConfigurationClient)} before getting the value!"); + return GetConfigurationByChecking(); } - protected virtual string CreateCacheKey() + private ApplicationConfigurationDto GetConfigurationByChecking() { - return $"ApplicationConfiguration"; + var configuration = Cache.Get(); + if (configuration == null) + { + throw new AbpException( + $"{nameof(WebAssemblyCachedApplicationConfigurationClient)} should be initialized before using it."); + } + + return configuration; } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentUser.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentPrincipalAccessor.cs similarity index 100% rename from framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentUser.cs rename to framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentPrincipalAccessor.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs index b179856842..f8502fce78 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/RemoteLocalizationContributor.cs @@ -4,7 +4,6 @@ using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Localization; -using Volo.Abp.Threading; namespace Volo.Abp.AspNetCore.Mvc.Client {