zoukankan      html  css  js  c++  java
  • Castle.Aop.Autofac

    https://github.com/mnoskovic/Castle.Aop

    同样是基于dynamicproxy的,支持autofac

    结果比snap靠谱

    aop 1 before
    aop 1 in
    aop 2 in
    real method runing
    aop 2 out
    aop 1 out
    aop 1 after

    顺序是希望的顺序

    可以继承StandardInterceptor或直接实现IInterceptor

    Interceptor(typeof(XXX))这个attribute做标记

    autofac需要

    var builder = new ContainerBuilder();
    builder.RegisterModule(new InterceptorModule());
    builder.RegisterType<Aop1>();
    builder.RegisterType<Aop2>();
    builder.RegisterType<TestHelper>().As<ITestHelper>();

    1、注册InterceptorModule

    2、注册aop类

    3、注册真正的类

    至少顺序比snap靠谱,性能未测试

    看看在aop里改参数

    aop 1 before
    p is 1; r is (is null:True)
    aop 1 in
    p is 2; r is (is null:True)
    aop 2 in
    p is 3; r is (is null:True)
    real method runing; r is 6
    aop 2 out
    p is 6; r is (is null:True)
    aop 1 out
    p is 7; r is (is null:True)
    aop 1 after
    p is 4; r is (is null:True)

    方法调用传入1,aop1的before改为2,aop1 process前改为3,process后改为4,aop1 after改为5,aop2 process前改为6,后改为7。

    实际传入的是6

    去掉6,实际传入的是3;去掉3,实际传入的是2,去掉2,实际传入的是1,基本上还是符合预想的。

    但是返回值就让我有点郁闷了,为什么都是null尼?方法执行完了还是null,这不扯呢嘛。而且外部调用确实也是没有收到返回值的。

  • 相关阅读:
    Linux下编译LibCURL
    Linux下编译OpenSSL
    Linux下编译UnixODBC
    Linux下编译Boost
    MySQL存储引擎【InnoDB、MyISAM、Memory】
    MySQL数据库MyISAM和InnoDB存储引擎的比较
    MySQL存储引擎MyISAM与InnoDB的优劣
    14款经典的MySQL客户端软件
    MySQL 数据类型
    MySQL数据库的基本数据类型
  • 原文地址:https://www.cnblogs.com/czcz1024/p/3119357.html
Copyright © 2011-2022 走看看