| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Reflection;
- namespace Abp.Aspects
- {
- //THIS NAMESPACE IS WORK-IN-PROGRESS
- internal abstract class AspectAttribute : Attribute
- {
- public Type InterceptorType { get; set; }
- protected AspectAttribute(Type interceptorType)
- {
- InterceptorType = interceptorType;
- }
- }
- internal interface IAbpInterceptionContext
- {
- object Target { get; }
- MethodInfo Method { get; }
- object[] Arguments { get; }
- object ReturnValue { get; }
- bool Handled { get; set; }
- }
- internal interface IAbpBeforeExecutionInterceptionContext : IAbpInterceptionContext
- {
- }
- internal interface IAbpAfterExecutionInterceptionContext : IAbpInterceptionContext
- {
- Exception Exception { get; }
- }
- internal interface IAbpInterceptor<TAspect>
- {
- TAspect Aspect { get; set; }
- void BeforeExecution(IAbpBeforeExecutionInterceptionContext context);
- void AfterExecution(IAbpAfterExecutionInterceptionContext context);
- }
- internal abstract class AbpInterceptorBase<TAspect> : IAbpInterceptor<TAspect>
- {
- public TAspect Aspect { get; set; }
- public virtual void BeforeExecution(IAbpBeforeExecutionInterceptionContext context)
- {
- }
- public virtual void AfterExecution(IAbpAfterExecutionInterceptionContext context)
- {
- }
- }
- internal class Test_Aspects
- {
- internal class MyAspectAttribute : AspectAttribute
- {
- public int TestValue { get; set; }
- public MyAspectAttribute()
- : base(typeof(MyInterceptor))
- {
- }
- }
- internal class MyInterceptor : AbpInterceptorBase<MyAspectAttribute>
- {
- public override void BeforeExecution(IAbpBeforeExecutionInterceptionContext context)
- {
- Aspect.TestValue++;
- }
- public override void AfterExecution(IAbpAfterExecutionInterceptionContext context)
- {
- Aspect.TestValue++;
- }
- }
- public class MyService
- {
- [MyAspect(TestValue = 41)] //Usage!
- public void DoIt()
- {
- }
- }
- public class MyClient
- {
- private readonly MyService _service;
- public MyClient(MyService service)
- {
- _service = service;
- }
- public void Test()
- {
- _service.DoIt();
- }
- }
- }
- }
|