-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
161 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/AbpAsyncDeterminationInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Castle.DynamicProxy; | ||
using Volo.Abp.DynamicProxy; | ||
|
||
namespace Volo.Abp.Castle.DynamicProxy | ||
{ | ||
public class AbpAsyncDeterminationInterceptor<TInterceptor> : AsyncDeterminationInterceptor | ||
where TInterceptor : IAbpInterceptor | ||
{ | ||
public AbpAsyncDeterminationInterceptor(TInterceptor abpInterceptor) | ||
: base(new CastleAsyncAbpInterceptorAdapter<TInterceptor>(abpInterceptor)) | ||
{ | ||
|
||
} | ||
} | ||
} |
73 changes: 0 additions & 73 deletions
73
...work/src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpInterceptorAdapter.cs
This file was deleted.
Oops, something went wrong.
55 changes: 8 additions & 47 deletions
55
...src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpMethodInvocationAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Castle.DynamicProxy; | ||
using Volo.Abp.DynamicProxy; | ||
using Volo.Abp.Threading; | ||
|
||
namespace Volo.Abp.Castle.DynamicProxy | ||
{ | ||
public class CastleAbpMethodInvocationAdapter : IAbpMethodInvocation | ||
public class CastleAbpMethodInvocationAdapter : CastleAbpMethodInvocationAdapterBase, IAbpMethodInvocation | ||
{ | ||
public object[] Arguments => Invocation.Arguments; | ||
|
||
public IReadOnlyDictionary<string, object> ArgumentsDictionary => _lazyArgumentsDictionary.Value; | ||
private readonly Lazy<IReadOnlyDictionary<string, object>> _lazyArgumentsDictionary; | ||
|
||
public Type[] GenericArguments => Invocation.GenericArguments; | ||
|
||
public object TargetObject => Invocation.InvocationTarget ?? Invocation.MethodInvocationTarget; | ||
|
||
public MethodInfo Method => Invocation.MethodInvocationTarget ?? Invocation.Method; | ||
|
||
public object ReturnValue | ||
{ | ||
get => _actualReturnValue ?? Invocation.ReturnValue; | ||
set => Invocation.ReturnValue = value; | ||
} | ||
|
||
private object _actualReturnValue; | ||
|
||
protected IInvocation Invocation { get; } | ||
protected IInvocationProceedInfo ProceedInfo { get; } | ||
protected Func<IInvocation, IInvocationProceedInfo, Task> Proceed { get; } | ||
|
||
public CastleAbpMethodInvocationAdapter(IInvocation invocation, IInvocationProceedInfo proceedInfo) | ||
public CastleAbpMethodInvocationAdapter(IInvocation invocation, IInvocationProceedInfo proceedInfo, | ||
Func<IInvocation, IInvocationProceedInfo, Task> proceed) | ||
: base(invocation) | ||
{ | ||
Invocation = invocation; | ||
ProceedInfo = proceedInfo; | ||
|
||
_lazyArgumentsDictionary = new Lazy<IReadOnlyDictionary<string, object>>(GetArgumentsDictionary); | ||
} | ||
|
||
public Task ProceedAsync() | ||
{ | ||
ProceedInfo.Invoke(); | ||
|
||
_actualReturnValue = Invocation.ReturnValue; | ||
|
||
return (Task) _actualReturnValue; | ||
Proceed = proceed; | ||
} | ||
|
||
private IReadOnlyDictionary<string, object> GetArgumentsDictionary() | ||
public override async Task ProceedAsync() | ||
{ | ||
var dict = new Dictionary<string, object>(); | ||
|
||
var methodParameters = Method.GetParameters(); | ||
for (int i = 0; i < methodParameters.Length; i++) | ||
{ | ||
dict[methodParameters[i].Name] = Invocation.Arguments[i]; | ||
} | ||
|
||
return dict; | ||
await Proceed(Invocation, ProceedInfo); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpMethodInvocationAdapterBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Castle.DynamicProxy; | ||
using Volo.Abp.DynamicProxy; | ||
|
||
namespace Volo.Abp.Castle.DynamicProxy | ||
{ | ||
public abstract class CastleAbpMethodInvocationAdapterBase : IAbpMethodInvocation | ||
{ | ||
public object[] Arguments => Invocation.Arguments; | ||
|
||
public IReadOnlyDictionary<string, object> ArgumentsDictionary => _lazyArgumentsDictionary.Value; | ||
private readonly Lazy<IReadOnlyDictionary<string, object>> _lazyArgumentsDictionary; | ||
|
||
public Type[] GenericArguments => Invocation.GenericArguments; | ||
|
||
public object TargetObject => Invocation.InvocationTarget ?? Invocation.MethodInvocationTarget; | ||
|
||
public MethodInfo Method => Invocation.MethodInvocationTarget ?? Invocation.Method; | ||
|
||
public object ReturnValue { get; set; } | ||
|
||
protected IInvocation Invocation { get; } | ||
|
||
protected CastleAbpMethodInvocationAdapterBase(IInvocation invocation) | ||
{ | ||
Invocation = invocation; | ||
_lazyArgumentsDictionary = new Lazy<IReadOnlyDictionary<string, object>>(GetArgumentsDictionary); | ||
} | ||
|
||
public abstract Task ProceedAsync(); | ||
|
||
private IReadOnlyDictionary<string, object> GetArgumentsDictionary() | ||
{ | ||
var dict = new Dictionary<string, object>(); | ||
|
||
var methodParameters = Method.GetParameters(); | ||
for (int i = 0; i < methodParameters.Length; i++) | ||
{ | ||
dict[methodParameters[i].Name] = Invocation.Arguments[i]; | ||
} | ||
|
||
return dict; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...stle.Core/Volo/Abp/Castle/DynamicProxy/CastleAbpMethodInvocationAdapterWithReturnValue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Castle.DynamicProxy; | ||
using Volo.Abp.DynamicProxy; | ||
|
||
namespace Volo.Abp.Castle.DynamicProxy | ||
{ | ||
public class CastleAbpMethodInvocationAdapterWithReturnValue<TResult> : CastleAbpMethodInvocationAdapterBase, IAbpMethodInvocation | ||
{ | ||
protected IInvocationProceedInfo ProceedInfo { get; } | ||
protected Func<IInvocation, IInvocationProceedInfo, Task<TResult>> Proceed { get; } | ||
|
||
public CastleAbpMethodInvocationAdapterWithReturnValue(IInvocation invocation, | ||
IInvocationProceedInfo proceedInfo, | ||
Func<IInvocation, IInvocationProceedInfo, Task<TResult>> proceed) | ||
: base(invocation) | ||
{ | ||
ProceedInfo = proceedInfo; | ||
Proceed = proceed; | ||
} | ||
|
||
public override async Task ProceedAsync() | ||
{ | ||
ReturnValue = await Proceed(Invocation, ProceedInfo); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...src/Volo.Abp.Castle.Core/Volo/Abp/Castle/DynamicProxy/CastleAsyncAbpInterceptorAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Castle.DynamicProxy; | ||
using Volo.Abp.DynamicProxy; | ||
|
||
namespace Volo.Abp.Castle.DynamicProxy | ||
{ | ||
public class CastleAsyncAbpInterceptorAdapter<TInterceptor> : AsyncInterceptorBase | ||
where TInterceptor : IAbpInterceptor | ||
{ | ||
private readonly TInterceptor _abpInterceptor; | ||
|
||
public CastleAsyncAbpInterceptorAdapter(TInterceptor abpInterceptor) | ||
{ | ||
_abpInterceptor = abpInterceptor; | ||
} | ||
|
||
protected override async Task InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func<IInvocation, IInvocationProceedInfo, Task> proceed) | ||
{ | ||
await _abpInterceptor.InterceptAsync( | ||
new CastleAbpMethodInvocationAdapter(invocation, proceedInfo, proceed) | ||
); | ||
} | ||
|
||
protected override async Task<TResult> InterceptAsync<TResult>(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func<IInvocation, IInvocationProceedInfo, Task<TResult>> proceed) | ||
{ | ||
var adapter = new CastleAbpMethodInvocationAdapterWithReturnValue<TResult>(invocation, proceedInfo, proceed); | ||
|
||
await _abpInterceptor.InterceptAsync( | ||
adapter | ||
); | ||
|
||
return (TResult)adapter.ReturnValue; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters