聊一下Castle DynamicProxy基本用法(AOP)
IT科技类资讯 2025-10-07 09:48:44
0

复制/// <summary> /// 为业务类添加AOP拦截器。聊下 /// </summary> public class InterceptorAttribute:PlutoStudio.Aop.InterceptorAttribute { /// <summary> /// 拦截方法的基本执行,源码库如果当前方法有拦截处理器,用法则执行处理器。亿华云聊下 /// </summary> /// <param name="invocation">被拦截的基本调用目标对象</param> public override void Intercept(IInvocation invocation) { var method = invocation.Method; var processors = method.GetCustomAttributes(typeof(IInterceptorProcessor),true).Cast<IInterceptorProcessor>().ToList(); processors.ForEach(p => PlutoStudio.MefContainer.Container.ComposeParts(p)); if (processors.Count>0) { processors.ForEach(p => p.PreProcess(invocation)); try { invocation.Proceed(); processors.ForEach(p => p.PostProcess(invocation, null)); } catch (Exception ex) { processors.ForEach(p => p.PostProcess(invocation, ex)); throw; } } else { invocation.Proceed(); } } } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.云服务器提供商