Browse Source

Merge pull request #807 from colinin/support-idempotent

feat(idempotent): add IgnoreIdempotentAttribute
pull/808/head
yx lin 3 years ago
committed by GitHub
parent
commit
7bcd0c715a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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;
namespace LINGYUN.Abp.Idempotent;
public interface IIdempotentChecker
{
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>
/// 自定义的幂等key
/// </summary>
public string? IdempotentKey { get; }
public string? IdempotentKey { get; set; }
public IdempotentAttribute()
{
}
public IdempotentAttribute(
string? iodempotentKey = null,
int? timeout = null,
string? redirectUrl = null,
string[]? keyMap = null)
{
IdempotentKey = iodempotentKey;
Timeout = timeout;
KeyMap = keyMap;
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;
}
[IgnoreIdempotent]
public async virtual Task CheckAsync(IdempotentCheckContext context)
{
if (!_idempotentOptions.IsEnabled)
@ -30,6 +31,11 @@ public class IdempotentChecker : IIdempotentChecker, ITransientDependency
return;
}
if (context.Method.IsDefined(typeof(IgnoreIdempotentAttribute), true))
{
return;
}
var attr = context.Method.GetCustomAttribute<IdempotentAttribute>();
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
{
[IgnoreIdempotent]
public virtual void Denied(IdempotentDeniedContext context)
{
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;
}
[IgnoreIdempotent]
public async override Task InterceptAsync(IAbpMethodInvocation invocation)
{
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;
}
[IgnoreIdempotent]
public virtual string NormalizeKey(IdempotentKeyNormalizerContext context)
{
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;
}
[IgnoreIdempotent]
public override void Wrap(HttpResponseWrapperContext context)
{
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
{
[IgnoreIdempotent]
public async virtual Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
if (!ShouldCheckIdempotent(context))

Loading…
Cancel
Save