From da38948e50e63f2fd0e52f34d6c3992114fefe26 Mon Sep 17 00:00:00 2001 From: maliming Date: Sun, 6 Apr 2025 10:52:43 +0800 Subject: [PATCH] Remove `ClientProxyServices` if `ExposeClientProxyServices` is `false`. --- .../AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs | 2 ++ .../Mvc/Conventions/AbpServiceConvention.cs | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs index 56acc2f745..548981053d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs @@ -16,6 +16,8 @@ public class AbpAspNetCoreMvcOptions public bool ExposeIntegrationServices { get; set; } = false; + public bool ExposeClientProxyServices { get; set; } = false; + public bool AutoModelValidation { get; set; } public bool EnableRazorRuntimeCompilationOnDevelopment { get; set; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention.cs index 3d3a71958a..31ba046250 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention.cs @@ -74,16 +74,29 @@ public class AbpServiceConvention : IAbpServiceConvention, ITransientDependency protected virtual void RemoveIntegrationControllersIfNotExposed(ApplicationModel application) { - if (Options.ExposeIntegrationServices) + if (!Options.ExposeIntegrationServices) { - return; + var integrationControllers = GetControllers(application) + .Where(c => IntegrationServiceAttribute.IsDefinedOrInherited(c.ControllerType)) + .ToArray(); + + application.Controllers.RemoveAll(integrationControllers); + } + + if (!Options.ExposeClientProxyServices) + { + var clientProxyServiceControllers = GetControllers(application) + .Where(c => IsClientProxyService(c.ControllerType)) + .ToArray(); + + application.Controllers.RemoveAll(clientProxyServiceControllers); } - - var integrationControllers = GetControllers(application) - .Where(c => IntegrationServiceAttribute.IsDefinedOrInherited(c.ControllerType)) - .ToArray(); + } - application.Controllers.RemoveAll(integrationControllers); + protected virtual bool IsClientProxyService(Type controllerType) + { + return typeof(IApplicationService).IsAssignableFrom(controllerType) && + controllerType.GetBaseClasses().Any(x => x.IsGenericType && x.GetGenericTypeDefinition().FullName!.StartsWith("Volo.Abp.Http.Client.ClientProxying.ClientProxyBase")); } protected virtual IList GetControllers(ApplicationModel application)