maliming
2 years ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
6 changed files with
43 additions and
41 deletions
-
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcActionDescriptorProvider.cs
-
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Filters/DisableAbpFilterAttribute.cs
-
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Middleware/AbpMiddlewareBase.cs
-
framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs
-
framework/src/Volo.Abp.Core/Volo/Abp/DisableAbpFeaturesAttribute.cs
-
framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/DisableAbpInterceptorAttribute.cs
|
|
|
@ -20,10 +20,11 @@ public class AbpMvcActionDescriptorProvider : IActionDescriptorProvider |
|
|
|
{ |
|
|
|
foreach (var action in context.Results.Where(x => x is ControllerActionDescriptor).Cast<ControllerActionDescriptor>()) |
|
|
|
{ |
|
|
|
var disableFilterAttribute = action.ControllerTypeInfo.GetCustomAttribute<DisableAbpFilterAttribute>(true); |
|
|
|
if (disableFilterAttribute != null) |
|
|
|
var disableAbpFeaturesAttribute = action.ControllerTypeInfo.GetCustomAttribute<DisableAbpFeaturesAttribute>(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)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -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<ControllerActionDescriptor>(); |
|
|
|
var disableAbpFilterAttribute = controllerActionDescriptor?.ControllerTypeInfo.GetCustomAttribute<DisableAbpFilterAttribute>(); |
|
|
|
return Task.FromResult(disableAbpFilterAttribute != null && disableAbpFilterAttribute.SkipInMiddleware); |
|
|
|
var disableAbpFeaturesAttribute = controllerActionDescriptor?.ControllerTypeInfo.GetCustomAttribute<DisableAbpFeaturesAttribute>(); |
|
|
|
return Task.FromResult(disableAbpFeaturesAttribute != null && disableAbpFeaturesAttribute.DisableMiddlewares); |
|
|
|
} |
|
|
|
|
|
|
|
public abstract Task InvokeAsync(HttpContext context, RequestDelegate next); |
|
|
|
|
|
|
|
@ -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<DisableAbpFeaturesAttribute>(true); |
|
|
|
if (disableAbpFeaturesAttribute == null || !disableAbpFeaturesAttribute.DisableInterceptors) |
|
|
|
{ |
|
|
|
registrationBuilder = registrationBuilder.AddInterceptors( |
|
|
|
registrationActionList, |
|
|
|
serviceType, |
|
|
|
serviceRegistredArgs.Interceptors |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return registrationBuilder; |
|
|
|
|
|
|
|
@ -0,0 +1,25 @@ |
|
|
|
using System; |
|
|
|
|
|
|
|
namespace Volo.Abp; |
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class)] |
|
|
|
public class DisableAbpFeaturesAttribute : Attribute |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// The framework will not register any interceptors for the class.
|
|
|
|
/// This will cause the all features that depend on interceptors to not work.
|
|
|
|
/// </summary>
|
|
|
|
public bool DisableInterceptors { get; set; } = true; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The framework middleware will skip the class.
|
|
|
|
/// This will cause the all features that depend on middleware to not work.
|
|
|
|
/// </summary>
|
|
|
|
public bool DisableMiddlewares { get; set; } = true; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 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.
|
|
|
|
/// </summary>
|
|
|
|
public bool DisableMvcFilters { get; set; } = true; |
|
|
|
} |
|
|
|
@ -1,9 +0,0 @@ |
|
|
|
using System; |
|
|
|
|
|
|
|
namespace Volo.Abp.DynamicProxy; |
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class)] |
|
|
|
public class DisableAbpInterceptorAttribute : Attribute |
|
|
|
{ |
|
|
|
|
|
|
|
} |