diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcActionDescriptorProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcActionDescriptorProvider.cs index 9131cd44d6..1ae2180e47 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcActionDescriptorProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcActionDescriptorProvider.cs @@ -20,10 +20,11 @@ public class AbpMvcActionDescriptorProvider : IActionDescriptorProvider { foreach (var action in context.Results.Where(x => x is ControllerActionDescriptor).Cast()) { - var disableFilterAttribute = action.ControllerTypeInfo.GetCustomAttribute(true); - if (disableFilterAttribute != null) + var disableAbpFeaturesAttribute = action.ControllerTypeInfo.GetCustomAttribute(true); + if (disableAbpFeaturesAttribute != null && disableAbpFeaturesAttribute.DisableMvcFilters) { - action.FilterDescriptors.RemoveAll(x => x.Filter is ServiceFilterAttribute serviceFilterAttribute && typeof(IAbpFilter).IsAssignableFrom(serviceFilterAttribute.ServiceType)); + action.FilterDescriptors.RemoveAll(x => x.Filter is ServiceFilterAttribute serviceFilterAttribute && + typeof(IAbpFilter).IsAssignableFrom(serviceFilterAttribute.ServiceType)); } } } diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Filters/DisableAbpFilterAttribute.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Filters/DisableAbpFilterAttribute.cs deleted file mode 100644 index 035c7b288f..0000000000 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Filters/DisableAbpFilterAttribute.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -namespace Volo.Abp.AspNetCore.Filters; - -[AttributeUsage(AttributeTargets.Class)] -public class DisableAbpFilterAttribute : Attribute -{ - public bool SkipInMiddleware { get; set; } - - public DisableAbpFilterAttribute() - { - SkipInMiddleware = true; - } - - public DisableAbpFilterAttribute(bool skipInMiddleware) - { - SkipInMiddleware = skipInMiddleware; - } -} diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Middleware/AbpMiddlewareBase.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Middleware/AbpMiddlewareBase.cs index bbf79ba22e..f41578da33 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Middleware/AbpMiddlewareBase.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Middleware/AbpMiddlewareBase.cs @@ -2,7 +2,6 @@ using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; -using Volo.Abp.AspNetCore.Filters; namespace Volo.Abp.AspNetCore.Middleware; @@ -12,8 +11,8 @@ public abstract class AbpMiddlewareBase : IMiddleware { var endpoint = context.GetEndpoint(); var controllerActionDescriptor = endpoint?.Metadata.GetMetadata(); - var disableAbpFilterAttribute = controllerActionDescriptor?.ControllerTypeInfo.GetCustomAttribute(); - return Task.FromResult(disableAbpFilterAttribute != null && disableAbpFilterAttribute.SkipInMiddleware); + var disableAbpFeaturesAttribute = controllerActionDescriptor?.ControllerTypeInfo.GetCustomAttribute(); + return Task.FromResult(disableAbpFeaturesAttribute != null && disableAbpFeaturesAttribute.DisableMiddlewares); } public abstract Task InvokeAsync(HttpContext context, RequestDelegate next); diff --git a/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs b/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs index de5effd86c..53216b03b9 100644 --- a/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs +++ b/framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using Autofac.Core; using Autofac.Extras.DynamicProxy; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; using Volo.Abp.Autofac; using Volo.Abp.Castle.DynamicProxy; using Volo.Abp.DependencyInjection; @@ -74,14 +76,17 @@ public static class AbpRegistrationBuilderExtensions registrationAction.Invoke(serviceRegistredArgs); } - if (serviceRegistredArgs.Interceptors.Any() && - !serviceRegistredArgs.ImplementationType.IsDefined(typeof(DisableAbpInterceptorAttribute), true)) + if (serviceRegistredArgs.Interceptors.Any()) { - registrationBuilder = registrationBuilder.AddInterceptors( - registrationActionList, - serviceType, - serviceRegistredArgs.Interceptors - ); + var disableAbpFeaturesAttribute = serviceRegistredArgs.ImplementationType.GetCustomAttribute(true); + if (disableAbpFeaturesAttribute == null || !disableAbpFeaturesAttribute.DisableInterceptors) + { + registrationBuilder = registrationBuilder.AddInterceptors( + registrationActionList, + serviceType, + serviceRegistredArgs.Interceptors + ); + } } return registrationBuilder; diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DisableAbpFeaturesAttribute.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DisableAbpFeaturesAttribute.cs new file mode 100644 index 0000000000..69f80446a6 --- /dev/null +++ b/framework/src/Volo.Abp.Core/Volo/Abp/DisableAbpFeaturesAttribute.cs @@ -0,0 +1,25 @@ +using System; + +namespace Volo.Abp; + +[AttributeUsage(AttributeTargets.Class)] +public class DisableAbpFeaturesAttribute : Attribute +{ + /// + /// The framework will not register any interceptors for the class. + /// This will cause the all features that depend on interceptors to not work. + /// + public bool DisableInterceptors { get; set; } = true; + + /// + /// The framework middleware will skip the class. + /// This will cause the all features that depend on middleware to not work. + /// + public bool DisableMiddlewares { get; set; } = true; + + /// + /// The framework will not remove all built-in filters for the class. + /// This will cause the all features that depend on filters to not work. + /// + public bool DisableMvcFilters { get; set; } = true; +} diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/DisableAbpInterceptorAttribute.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/DisableAbpInterceptorAttribute.cs deleted file mode 100644 index be7b773c87..0000000000 --- a/framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/DisableAbpInterceptorAttribute.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace Volo.Abp.DynamicProxy; - -[AttributeUsage(AttributeTargets.Class)] -public class DisableAbpInterceptorAttribute : Attribute -{ - -}