zoukankan      html  css  js  c++  java
  • net 5 aop

      接口处 声明一个切入逻辑

     标记接口 所有的方法都要aop 了

       [Intercept(typeof(CustomAutofactAOP))]
        public interface Itest
        {
            public void hello();
         
        }
     public class CustomAutofactAOP : IInterceptor
        {
            public void Intercept(IInvocation invocation)
            {
                {
                    Console.WriteLine("执行前。。。。");
                }
                invocation.Proceed();// 
                {
                    Console.WriteLine("执行后。。。。");
                }
            }
        }

    针对接口注册

           public static void  RegsterType(this ContainerBuilder builder)
            {
    
                builder.RegisterType<CustomAutofactAOP>();
                builder.RegisterType<test>().As<Itest>().EnableInterfaceInterceptors();
                builder.RegisterType<CustomAuthorizationHandler>().As<IAuthorizationHandler>();
                builder.RegisterType<World>().As<IWorld>().PropertiesAutowired(new CustomPropertySelector());
            }


    调用hello 方法
    
    
    
    运行结果 


    
    

     还有通过虚方法aop  这样细节到具体方法 而不是所有接口类都aop

    
    
    
               1 builder.RegisterType<test>().As<Itest>().EnableInterfaceInterceptors(); 换成 builder.RegisterType<test>().As<Itest>().Enablec1assInterceptors();
    2 在具体实现的抽象类上标记拦截器   [Intercept(typeof(CustomAutofactAOP))] 放在整个实现类上 需要aop的方法 标记虚方法 virtual 即可完成aop


  • 相关阅读:
    BOMwindow对象
    函数
    js 页面定时刷新
    appcan中 模拟表单上传图片
    商品评价多图片分组上传
    微信发送通知消息 thinkphp
    微信页面的分享,设置分享信息以及监听分享
    微信异步通知出错,behavior原因
    清空session
    json_decode
  • 原文地址:https://www.cnblogs.com/jasontarry/p/15330703.html
Copyright © 2011-2022 走看看