Browse Source

feat(idempotent): add IgnoreIdempotentAttribute

pull/807/head
cKey 3 years ago
parent
commit
8c2178016a
  1. 1
      aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IIdempotentChecker.cs
  2. 4
      aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IdempotentAttribute.cs
  3. 6
      aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IdempotentChecker.cs
  4. 1
      aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IdempotentDeniedHandler.cs
  5. 1
      aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IdempotentInterceptor.cs
  6. 1
      aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IdempotentKeyNormalizer.cs
  7. 8
      aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IgnoreIdempotentAttribute.cs
  8. 1
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Idempotent.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Idempotent/Wrapper/IdempotentHttpResponseWrapper.cs
  9. 1
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Idempotent/LINGYUN/Abp/AspNetCore/Mvc/Idempotent/AbpIdempotentActionFilter.cs

1
aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IIdempotentChecker.cs

@ -1,6 +1,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace LINGYUN.Abp.Idempotent; namespace LINGYUN.Abp.Idempotent;
public interface IIdempotentChecker public interface IIdempotentChecker
{ {
Task CheckAsync(IdempotentCheckContext context); Task CheckAsync(IdempotentCheckContext context);

4
aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IdempotentAttribute.cs

@ -30,17 +30,19 @@ public class IdempotentAttribute : Attribute
/// <summary> /// <summary>
/// 自定义的幂等key /// 自定义的幂等key
/// </summary> /// </summary>
public string? IdempotentKey { get; } public string? IdempotentKey { get; set; }
public IdempotentAttribute() public IdempotentAttribute()
{ {
} }
public IdempotentAttribute( public IdempotentAttribute(
string? iodempotentKey = null,
int? timeout = null, int? timeout = null,
string? redirectUrl = null, string? redirectUrl = null,
string[]? keyMap = null) string[]? keyMap = null)
{ {
IdempotentKey = iodempotentKey;
Timeout = timeout; Timeout = timeout;
KeyMap = keyMap; KeyMap = keyMap;
RedirectUrl = redirectUrl; RedirectUrl = redirectUrl;

6
aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IdempotentChecker.cs

@ -23,6 +23,7 @@ public class IdempotentChecker : IIdempotentChecker, ITransientDependency
_idempotentDeniedHandler = idempotentDeniedHandler; _idempotentDeniedHandler = idempotentDeniedHandler;
} }
[IgnoreIdempotent]
public async virtual Task CheckAsync(IdempotentCheckContext context) public async virtual Task CheckAsync(IdempotentCheckContext context)
{ {
if (!_idempotentOptions.IsEnabled) if (!_idempotentOptions.IsEnabled)
@ -30,6 +31,11 @@ public class IdempotentChecker : IIdempotentChecker, ITransientDependency
return; return;
} }
if (context.Method.IsDefined(typeof(IgnoreIdempotentAttribute), true))
{
return;
}
var attr = context.Method.GetCustomAttribute<IdempotentAttribute>(); var attr = context.Method.GetCustomAttribute<IdempotentAttribute>();
var methodLockTimeout = _idempotentOptions.DefaultTimeout; var methodLockTimeout = _idempotentOptions.DefaultTimeout;

1
aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IdempotentDeniedHandler.cs

@ -6,6 +6,7 @@ namespace LINGYUN.Abp.Idempotent;
public class IdempotentDeniedHandler : IIdempotentDeniedHandler, ISingletonDependency public class IdempotentDeniedHandler : IIdempotentDeniedHandler, ISingletonDependency
{ {
[IgnoreIdempotent]
public virtual void Denied(IdempotentDeniedContext context) public virtual void Denied(IdempotentDeniedContext context)
{ {
var exception = new IdempotentDeniedException(context.IdempotentKey, IdempotentErrorCodes.IdempotentDenied) var exception = new IdempotentDeniedException(context.IdempotentKey, IdempotentErrorCodes.IdempotentDenied)

1
aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IdempotentInterceptor.cs

@ -17,6 +17,7 @@ public class IdempotentInterceptor : AbpInterceptor, ITransientDependency
_idempotentKeyNormalizer = idempotentKeyNormalizer; _idempotentKeyNormalizer = idempotentKeyNormalizer;
} }
[IgnoreIdempotent]
public async override Task InterceptAsync(IAbpMethodInvocation invocation) public async override Task InterceptAsync(IAbpMethodInvocation invocation)
{ {
var targetType = ProxyHelper.GetUnProxiedType(invocation.TargetObject); var targetType = ProxyHelper.GetUnProxiedType(invocation.TargetObject);

1
aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IdempotentKeyNormalizer.cs

@ -18,6 +18,7 @@ public class IdempotentKeyNormalizer : IIdempotentKeyNormalizer, ITransientDepen
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
} }
[IgnoreIdempotent]
public virtual string NormalizeKey(IdempotentKeyNormalizerContext context) public virtual string NormalizeKey(IdempotentKeyNormalizerContext context)
{ {
var methodIdBuilder = new StringBuilder(); var methodIdBuilder = new StringBuilder();

8
aspnet-core/modules/common/LINGYUN.Abp.Idempotent/LINGYUN/Abp/Idempotent/IgnoreIdempotentAttribute.cs

@ -0,0 +1,8 @@
using System;
namespace LINGYUN.Abp.Idempotent;
[AttributeUsage(AttributeTargets.Method)]
public class IgnoreIdempotentAttribute : Attribute
{
}

1
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Idempotent.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Idempotent/Wrapper/IdempotentHttpResponseWrapper.cs

@ -21,6 +21,7 @@ public class IdempotentHttpResponseWrapper : HttpResponseWrapper, ITransientDepe
IdempotentOptions = idempotentOptions.Value; IdempotentOptions = idempotentOptions.Value;
} }
[IgnoreIdempotent]
public override void Wrap(HttpResponseWrapperContext context) public override void Wrap(HttpResponseWrapperContext context)
{ {
if (context.HttpContext.Items.TryGetValue(nameof(IdempotentAttribute.RedirectUrl), out var redirectUrl) && redirectUrl != null) if (context.HttpContext.Items.TryGetValue(nameof(IdempotentAttribute.RedirectUrl), out var redirectUrl) && redirectUrl != null)

1
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Idempotent/LINGYUN/Abp/AspNetCore/Mvc/Idempotent/AbpIdempotentActionFilter.cs

@ -12,6 +12,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Idempotent;
public class AbpIdempotentActionFilter : IAsyncActionFilter, ITransientDependency public class AbpIdempotentActionFilter : IAsyncActionFilter, ITransientDependency
{ {
[IgnoreIdempotent]
public async virtual Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) public async virtual Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{ {
if (!ShouldCheckIdempotent(context)) if (!ShouldCheckIdempotent(context))

Loading…
Cancel
Save