mirror of https://github.com/abpframework/abp.git
10 changed files with 153 additions and 38 deletions
@ -1,22 +1,12 @@ |
|||||
using System; |
using Volo.Abp.DynamicProxy; |
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Volo.Abp.Castle.DynamicProxy; |
|
||||
using Volo.Abp.DynamicProxy; |
|
||||
|
|
||||
namespace Volo.Abp.Autofac.Interception |
namespace Volo.Abp.Autofac.Interception |
||||
{ |
{ |
||||
public class Autofac_Interception_Test : AbpInterceptionTestBase<AutofacTestModule> |
public class Autofac_Interception_Test : AbpInterceptionTestBase<AutofacTestModule> |
||||
{ |
{ |
||||
//TODO: Sımplify using autofac in tests!
|
|
||||
|
|
||||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
||||
{ |
{ |
||||
options.UseAutofac(); |
options.UseAutofac(); |
||||
} |
} |
||||
|
|
||||
protected override IServiceProvider CreateServiceProvider(IServiceCollection services) |
|
||||
{ |
|
||||
return services.BuildAutofacServiceProvider(); |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,18 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.DynamicProxy |
||||
|
{ |
||||
|
public class CachedTestObject |
||||
|
{ |
||||
|
public virtual int GetValue(int v) |
||||
|
{ |
||||
|
return v; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<int> GetValueAsync(int v) |
||||
|
{ |
||||
|
await Task.Delay(5); |
||||
|
return v; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
using System.Collections.Concurrent; |
||||
|
using System.Reflection; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.DynamicProxy |
||||
|
{ |
||||
|
public class SimpleResultCacheTestInterceptor : AbpInterceptor |
||||
|
{ |
||||
|
private readonly ConcurrentDictionary<MethodInfo, object> _cache; |
||||
|
|
||||
|
public SimpleResultCacheTestInterceptor() |
||||
|
{ |
||||
|
_cache = new ConcurrentDictionary<MethodInfo, object>(); |
||||
|
} |
||||
|
|
||||
|
public override void Intercept(IAbpMethodInvocation invocation) |
||||
|
{ |
||||
|
invocation.ReturnValue = _cache.GetOrAdd(invocation.Method, m => |
||||
|
{ |
||||
|
invocation.Proceed(); |
||||
|
return invocation.ReturnValue; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public override async Task InterceptAsync(IAbpMethodInvocation invocation) |
||||
|
{ |
||||
|
if (_cache.ContainsKey(invocation.Method)) |
||||
|
{ |
||||
|
invocation.ReturnValue = _cache[invocation.Method]; |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
await invocation.ProceedAsync(); |
||||
|
_cache[invocation.Method] = invocation.ReturnValue; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue