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


  • 相关阅读:
    Flexbox兼容性
    响应式布局(Responsive Layout)/流式布局(Fluid Layout)/自适应布局(Adaptive)
    Flex布局之box-flex
    Flex布局(伸缩盒布局)
    input美化问题
    用纯css改变下拉列表select框的默认样式
    超越icon font
    CSS居中之美
    php中yaf框架的服务器配置
    MySQL优化
  • 原文地址:https://www.cnblogs.com/jasontarry/p/15330703.html
Copyright © 2011-2022 走看看