From 991538fea4ed52dab1dec39b81d2da47b9f3e6f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 25 Sep 2020 19:23:30 +0300 Subject: [PATCH] Make ICurrentTenant working for the Blazor UI --- ...semblyCachedApplicationConfigurationClient.cs | 16 ++++++++++++++-- .../WebAssemblyCurrentTenantAccessor.cs | 11 +++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentTenantAccessor.cs 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 807e52fa17..d71b97334a 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 @@ -3,6 +3,7 @@ using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; using Volo.Abp.AspNetCore.Mvc.Client; using Volo.Abp.DependencyInjection; using Volo.Abp.Http.Client.DynamicProxying; +using Volo.Abp.MultiTenancy; namespace Volo.Abp.AspNetCore.Components.WebAssembly { @@ -17,17 +18,28 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly protected ApplicationConfigurationCache Cache { get; } + protected ICurrentTenantAccessor CurrentTenantAccessor { get; } + public WebAssemblyCachedApplicationConfigurationClient( IHttpClientProxy proxy, - ApplicationConfigurationCache cache) + ApplicationConfigurationCache cache, + ICurrentTenantAccessor currentTenantAccessor) { Proxy = proxy; Cache = cache; + CurrentTenantAccessor = currentTenantAccessor; } public virtual async Task InitializeAsync() { - Cache.Set(await Proxy.Service.GetAsync()); + var configurationDto = await Proxy.Service.GetAsync(); + + Cache.Set(configurationDto); + + CurrentTenantAccessor.Current = new BasicTenantInfo( + configurationDto.CurrentTenant.Id, + configurationDto.CurrentTenant.Name + ); } public virtual Task GetAsync() diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentTenantAccessor.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentTenantAccessor.cs new file mode 100644 index 0000000000..eb0ee781ad --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/WebAssemblyCurrentTenantAccessor.cs @@ -0,0 +1,11 @@ +using Volo.Abp.DependencyInjection; +using Volo.Abp.MultiTenancy; + +namespace Volo.Abp.AspNetCore.Components.WebAssembly +{ + [Dependency(ReplaceServices = true)] + public class WebAssemblyCurrentTenantAccessor : ICurrentTenantAccessor, ISingletonDependency + { + public BasicTenantInfo Current { get; set; } + } +}