Browse Source

Add `DisableAbpFeaturesAttribute`.

pull/18638/head
maliming 2 years ago
parent
commit
b10761d997
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 7
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcActionDescriptorProvider.cs
  2. 19
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Filters/DisableAbpFilterAttribute.cs
  3. 5
      framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Middleware/AbpMiddlewareBase.cs
  4. 19
      framework/src/Volo.Abp.Autofac/Autofac/Builder/AbpRegistrationBuilderExtensions.cs
  5. 25
      framework/src/Volo.Abp.Core/Volo/Abp/DisableAbpFeaturesAttribute.cs
  6. 9
      framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/DisableAbpInterceptorAttribute.cs

7
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<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));
}
}
}

19
framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/Filters/DisableAbpFilterAttribute.cs

@ -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;
}
}

5
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<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);

19
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<DisableAbpFeaturesAttribute>(true);
if (disableAbpFeaturesAttribute == null || !disableAbpFeaturesAttribute.DisableInterceptors)
{
registrationBuilder = registrationBuilder.AddInterceptors(
registrationActionList,
serviceType,
serviceRegistredArgs.Interceptors
);
}
}
return registrationBuilder;

25
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
{
/// <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;
}

9
framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/DisableAbpInterceptorAttribute.cs

@ -1,9 +0,0 @@
using System;
namespace Volo.Abp.DynamicProxy;
[AttributeUsage(AttributeTargets.Class)]
public class DisableAbpInterceptorAttribute : Attribute
{
}
Loading…
Cancel
Save