mirror of https://github.com/abpframework/abp.git
30 changed files with 150 additions and 38 deletions
@ -0,0 +1,30 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc.Abstractions; |
|||
using Microsoft.AspNetCore.Mvc.Controllers; |
|||
using Volo.Abp.AspNetCore.Filters; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.ApplicationModels; |
|||
|
|||
public class AbpMvcActionDescriptorProvider : IActionDescriptorProvider |
|||
{ |
|||
public virtual int Order => -1000 + 10; |
|||
|
|||
public virtual void OnProvidersExecuting(ActionDescriptorProviderContext context) |
|||
{ |
|||
} |
|||
|
|||
public virtual void OnProvidersExecuted(ActionDescriptorProviderContext context) |
|||
{ |
|||
foreach (var action in context.Results.Where(x => x is ControllerActionDescriptor).Cast<ControllerActionDescriptor>()) |
|||
{ |
|||
var disableFilterAttribute = action.ControllerTypeInfo.GetCustomAttribute<DisableAbpFilterAttribute>(true); |
|||
if (disableFilterAttribute != null) |
|||
{ |
|||
action.FilterDescriptors.RemoveAll(x => x.Filter is ServiceFilterAttribute serviceFilterAttribute && typeof(IAbpFilter).IsAssignableFrom(serviceFilterAttribute.ServiceType)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
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; |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace Volo.Abp.AspNetCore.Filters; |
|||
|
|||
public interface IAbpFilter |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
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; |
|||
|
|||
public abstract class AbpMiddlewareBase : IMiddleware |
|||
{ |
|||
protected Task<bool> ShouldSkipAsync(HttpContext context, RequestDelegate next) |
|||
{ |
|||
var endpoint = context.GetEndpoint(); |
|||
var controllerActionDescriptor = endpoint?.Metadata.GetMetadata<ControllerActionDescriptor>(); |
|||
var disableAbpFilterAttribute = controllerActionDescriptor?.ControllerTypeInfo.GetCustomAttribute<DisableAbpFilterAttribute>(); |
|||
return Task.FromResult(disableAbpFilterAttribute != null && disableAbpFilterAttribute.SkipInMiddleware); |
|||
} |
|||
|
|||
public abstract Task InvokeAsync(HttpContext context, RequestDelegate next); |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.DynamicProxy; |
|||
|
|||
[AttributeUsage(AttributeTargets.Class)] |
|||
public class DisableInterceptorAttribute : Attribute |
|||
{ |
|||
|
|||
} |
|||
Loading…
Reference in new issue