From e79b109da5e0360e0c778253791d395de493898f Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 4 Nov 2021 20:20:49 +0800 Subject: [PATCH] Add static proxy for `Volo.Abp.AspNetCore.Mvc.Client.Common`. Resolve #10518 --- ...blyCachedApplicationConfigurationClient.cs | 10 +- ...ationConfigurationClientProxy.Generated.cs | 23 +++ .../AbpApplicationConfigurationClientProxy.cs | 8 + .../AbpTenantClientProxy.Generated.cs | 34 ++++ .../ClientProxies/AbpTenantClientProxy.cs | 8 + .../ClientProxies/abp-generate-proxy.json | 169 ++++++++++++++++++ ...lo.Abp.AspNetCore.Mvc.Client.Common.csproj | 4 + .../AbpAspNetCoreMvcClientCommonModule.cs | 15 +- ...MvcCachedApplicationConfigurationClient.cs | 11 +- .../Mvc/Client/MvcRemoteTenantStore.cs | 16 +- 10 files changed, 273 insertions(+), 25 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpApplicationConfigurationClientProxy.Generated.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpApplicationConfigurationClientProxy.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpTenantClientProxy.Generated.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpTenantClientProxy.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/abp-generate-proxy.json 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 d71b97334a..c7b659a859 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,8 +1,8 @@ using System.Threading.Tasks; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ClientProxies; 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 @@ -14,25 +14,25 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly )] public class WebAssemblyCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency { - protected IHttpClientProxy Proxy { get; } + protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; } protected ApplicationConfigurationCache Cache { get; } protected ICurrentTenantAccessor CurrentTenantAccessor { get; } public WebAssemblyCachedApplicationConfigurationClient( - IHttpClientProxy proxy, + AbpApplicationConfigurationClientProxy applicationConfigurationAppService, ApplicationConfigurationCache cache, ICurrentTenantAccessor currentTenantAccessor) { - Proxy = proxy; + ApplicationConfigurationAppService = applicationConfigurationAppService; Cache = cache; CurrentTenantAccessor = currentTenantAccessor; } public virtual async Task InitializeAsync() { - var configurationDto = await Proxy.Service.GetAsync(); + var configurationDto = await ApplicationConfigurationAppService.GetAsync(); Cache.Set(configurationDto); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpApplicationConfigurationClientProxy.Generated.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpApplicationConfigurationClientProxy.Generated.cs new file mode 100644 index 0000000000..9d1c472bc7 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpApplicationConfigurationClientProxy.Generated.cs @@ -0,0 +1,23 @@ +// This file is automatically generated by ABP framework to use MVC Controllers from CSharp +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Http.Client; +using Volo.Abp.Http.Modeling; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.ClientProxying; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; + +// ReSharper disable once CheckNamespace +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ClientProxies +{ + [Dependency(ReplaceServices = true)] + [ExposeServices(typeof(IAbpApplicationConfigurationAppService), typeof(AbpApplicationConfigurationClientProxy))] + public partial class AbpApplicationConfigurationClientProxy : ClientProxyBase, IAbpApplicationConfigurationAppService + { + public virtual async Task GetAsync() + { + return await RequestAsync(nameof(GetAsync)); + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpApplicationConfigurationClientProxy.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpApplicationConfigurationClientProxy.cs new file mode 100644 index 0000000000..dfe8e66417 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpApplicationConfigurationClientProxy.cs @@ -0,0 +1,8 @@ +// This file is part of AbpApplicationConfigurationClientProxy, you can customize it here +// ReSharper disable once CheckNamespace +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ClientProxies +{ + public partial class AbpApplicationConfigurationClientProxy + { + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpTenantClientProxy.Generated.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpTenantClientProxy.Generated.cs new file mode 100644 index 0000000000..8984abfc4c --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpTenantClientProxy.Generated.cs @@ -0,0 +1,34 @@ +// This file is automatically generated by ABP framework to use MVC Controllers from CSharp +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Http.Client; +using Volo.Abp.Http.Modeling; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.ClientProxying; +using Volo.Abp.AspNetCore.Mvc.MultiTenancy; + +// ReSharper disable once CheckNamespace +namespace Pages.Abp.MultiTenancy.ClientProxies +{ + [Dependency(ReplaceServices = true)] + [ExposeServices(typeof(IAbpTenantAppService), typeof(AbpTenantClientProxy))] + public partial class AbpTenantClientProxy : ClientProxyBase, IAbpTenantAppService + { + public virtual async Task FindTenantByNameAsync(string name) + { + return await RequestAsync(nameof(FindTenantByNameAsync), new ClientProxyRequestTypeValue + { + { typeof(string), name } + }); + } + + public virtual async Task FindTenantByIdAsync(Guid id) + { + return await RequestAsync(nameof(FindTenantByIdAsync), new ClientProxyRequestTypeValue + { + { typeof(Guid), id } + }); + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpTenantClientProxy.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpTenantClientProxy.cs new file mode 100644 index 0000000000..e8384e04b2 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/AbpTenantClientProxy.cs @@ -0,0 +1,8 @@ +// This file is part of AbpTenantClientProxy, you can customize it here +// ReSharper disable once CheckNamespace +namespace Pages.Abp.MultiTenancy.ClientProxies +{ + public partial class AbpTenantClientProxy + { + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/abp-generate-proxy.json b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/abp-generate-proxy.json new file mode 100644 index 0000000000..bf15515078 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/ClientProxies/abp-generate-proxy.json @@ -0,0 +1,169 @@ +{ + "modules": { + "abp": { + "rootPath": "abp", + "remoteServiceName": "abp", + "controllers": { + "Pages.Abp.MultiTenancy.AbpTenantController": { + "controllerName": "AbpTenant", + "controllerGroupName": "AbpTenant", + "type": "Pages.Abp.MultiTenancy.AbpTenantController", + "interfaces": [ + { + "type": "Volo.Abp.AspNetCore.Mvc.MultiTenancy.IAbpTenantAppService" + } + ], + "actions": { + "FindTenantByNameAsyncByName": { + "uniqueName": "FindTenantByNameAsyncByName", + "name": "FindTenantByNameAsync", + "httpMethod": "GET", + "url": "api/abp/multi-tenancy/tenants/by-name/{name}", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "name", + "typeAsString": "System.String, System.Private.CoreLib", + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "name", + "name": "name", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": [], + "bindingSourceId": "Path", + "descriptorName": "" + } + ], + "returnValue": { + "type": "Volo.Abp.AspNetCore.Mvc.MultiTenancy.FindTenantResultDto", + "typeSimple": "Volo.Abp.AspNetCore.Mvc.MultiTenancy.FindTenantResultDto" + }, + "allowAnonymous": null, + "implementFrom": "Volo.Abp.AspNetCore.Mvc.MultiTenancy.IAbpTenantAppService" + }, + "FindTenantByIdAsyncById": { + "uniqueName": "FindTenantByIdAsyncById", + "name": "FindTenantByIdAsync", + "httpMethod": "GET", + "url": "api/abp/multi-tenancy/tenants/by-id/{id}", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "id", + "typeAsString": "System.Guid, System.Private.CoreLib", + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "id", + "name": "id", + "jsonName": null, + "type": "System.Guid", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": [], + "bindingSourceId": "Path", + "descriptorName": "" + } + ], + "returnValue": { + "type": "Volo.Abp.AspNetCore.Mvc.MultiTenancy.FindTenantResultDto", + "typeSimple": "Volo.Abp.AspNetCore.Mvc.MultiTenancy.FindTenantResultDto" + }, + "allowAnonymous": null, + "implementFrom": "Volo.Abp.AspNetCore.Mvc.MultiTenancy.IAbpTenantAppService" + } + } + }, + "Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.AbpApplicationConfigurationController": { + "controllerName": "AbpApplicationConfiguration", + "controllerGroupName": "AbpApplicationConfiguration", + "type": "Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.AbpApplicationConfigurationController", + "interfaces": [ + { + "type": "Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.IAbpApplicationConfigurationAppService" + } + ], + "actions": { + "GetAsync": { + "uniqueName": "GetAsync", + "name": "GetAsync", + "httpMethod": "GET", + "url": "api/abp/application-configuration", + "supportedVersions": [], + "parametersOnMethod": [], + "parameters": [], + "returnValue": { + "type": "Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ApplicationConfigurationDto", + "typeSimple": "Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ApplicationConfigurationDto" + }, + "allowAnonymous": null, + "implementFrom": "Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.IAbpApplicationConfigurationAppService" + } + } + }, + "Volo.Abp.AspNetCore.Mvc.ApiExploring.AbpApiDefinitionController": { + "controllerName": "AbpApiDefinition", + "controllerGroupName": "AbpApiDefinition", + "type": "Volo.Abp.AspNetCore.Mvc.ApiExploring.AbpApiDefinitionController", + "interfaces": [], + "actions": { + "GetByModel": { + "uniqueName": "GetByModel", + "name": "Get", + "httpMethod": "GET", + "url": "api/abp/api-definition", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "model", + "typeAsString": "Volo.Abp.Http.Modeling.ApplicationApiDescriptionModelRequestDto, Volo.Abp.Http", + "type": "Volo.Abp.Http.Modeling.ApplicationApiDescriptionModelRequestDto", + "typeSimple": "Volo.Abp.Http.Modeling.ApplicationApiDescriptionModelRequestDto", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "model", + "name": "IncludeTypes", + "jsonName": null, + "type": "System.Boolean", + "typeSimple": "boolean", + "isOptional": false, + "defaultValue": null, + "constraintTypes": null, + "bindingSourceId": "ModelBinding", + "descriptorName": "model" + } + ], + "returnValue": { + "type": "Volo.Abp.Http.Modeling.ApplicationApiDescriptionModel", + "typeSimple": "Volo.Abp.Http.Modeling.ApplicationApiDescriptionModel" + }, + "allowAnonymous": null, + "implementFrom": "Volo.Abp.AspNetCore.Mvc.ApiExploring.AbpApiDefinitionController" + } + } + } + } + } + }, + "types": {} +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo.Abp.AspNetCore.Mvc.Client.Common.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo.Abp.AspNetCore.Mvc.Client.Common.csproj index b509a5df59..1c1f4ef696 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo.Abp.AspNetCore.Mvc.Client.Common.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo.Abp.AspNetCore.Mvc.Client.Common.csproj @@ -23,4 +23,8 @@ + + + + diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientCommonModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientCommonModule.cs index b37c9d57fd..394a84e220 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientCommonModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client.Common/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientCommonModule.cs @@ -5,6 +5,7 @@ using Volo.Abp.Features; using Volo.Abp.Http.Client; using Volo.Abp.Localization; using Volo.Abp.Modularity; +using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.AspNetCore.Mvc.Client { @@ -14,7 +15,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Client typeof(AbpCachingModule), typeof(AbpLocalizationModule), typeof(AbpAuthorizationModule), - typeof(AbpFeaturesModule) + typeof(AbpFeaturesModule), + typeof(AbpVirtualFileSystemModule) )] public class AbpAspNetCoreMvcClientCommonModule : AbpModule { @@ -22,11 +24,12 @@ namespace Volo.Abp.AspNetCore.Mvc.Client public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddHttpClientProxies( - typeof(AbpAspNetCoreMvcContractsModule).Assembly, - RemoteServiceName, - asDefaultServices: false - ); + context.Services.AddStaticHttpClientProxies(typeof(AbpAspNetCoreMvcContractsModule).Assembly, RemoteServiceName); + + Configure(options => + { + options.FileSets.AddEmbedded(); + }); Configure(options => { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs index 4f5b7c84b0..b2f77315fb 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs @@ -1,12 +1,11 @@ using System; -using System.Globalization; using Microsoft.AspNetCore.Http; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Distributed; using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ClientProxies; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; -using Volo.Abp.Http.Client.DynamicProxying; using Volo.Abp.Threading; using Volo.Abp.Users; @@ -20,17 +19,17 @@ namespace Volo.Abp.AspNetCore.Mvc.Client public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency { protected IHttpContextAccessor HttpContextAccessor { get; } - protected IHttpClientProxy Proxy { get; } + protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; } protected ICurrentUser CurrentUser { get; } protected IDistributedCache Cache { get; } public MvcCachedApplicationConfigurationClient( IDistributedCache cache, - IHttpClientProxy proxy, + AbpApplicationConfigurationClientProxy applicationConfigurationAppService, ICurrentUser currentUser, IHttpContextAccessor httpContextAccessor) { - Proxy = proxy; + ApplicationConfigurationAppService = applicationConfigurationAppService; CurrentUser = currentUser; HttpContextAccessor = httpContextAccessor; Cache = cache; @@ -53,7 +52,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Client configuration = await Cache.GetOrAddAsync( cacheKey, - async () => await Proxy.Service.GetAsync(), + async () => await ApplicationConfigurationAppService.GetAsync(), () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(300) //TODO: Should be configurable. diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs index 2b6a272d64..f4744ca587 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/MvcRemoteTenantStore.cs @@ -2,10 +2,10 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Caching.Distributed; +using Pages.Abp.MultiTenancy.ClientProxies; using Volo.Abp.AspNetCore.Mvc.MultiTenancy; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; -using Volo.Abp.Http.Client.DynamicProxying; using Volo.Abp.MultiTenancy; using Volo.Abp.Threading; @@ -13,16 +13,16 @@ namespace Volo.Abp.AspNetCore.Mvc.Client { public class MvcRemoteTenantStore : ITenantStore, ITransientDependency { - protected IHttpClientProxy Proxy { get; } + protected AbpTenantClientProxy TenantAppService { get; } protected IHttpContextAccessor HttpContextAccessor { get; } protected IDistributedCache Cache { get; } public MvcRemoteTenantStore( - IHttpClientProxy proxy, + AbpTenantClientProxy tenantAppService, IHttpContextAccessor httpContextAccessor, IDistributedCache cache) { - Proxy = proxy; + TenantAppService = tenantAppService; HttpContextAccessor = httpContextAccessor; Cache = cache; } @@ -39,7 +39,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Client tenantConfiguration = await Cache.GetOrAddAsync( cacheKey, - async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByNameAsync(name)), + async () => CreateTenantConfiguration(await TenantAppService.FindTenantByNameAsync(name)), () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = @@ -67,7 +67,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Client tenantConfiguration = await Cache.GetOrAddAsync( cacheKey, - async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByIdAsync(id)), + async () => CreateTenantConfiguration(await TenantAppService.FindTenantByIdAsync(id)), () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = @@ -95,7 +95,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Client tenantConfiguration = Cache.GetOrAdd( cacheKey, - () => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByNameAsync(name))), + () => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await TenantAppService.FindTenantByNameAsync(name))), () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = @@ -123,7 +123,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Client tenantConfiguration = Cache.GetOrAdd( cacheKey, - () => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByIdAsync(id))), + () => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await TenantAppService.FindTenantByIdAsync(id))), () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow =