刚刚完成了一个c#的spring aop简单例子,是在mac下用Xamarin Studio开发的。代码如下:

接口

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace aoptest
{
public interface ISay
{
void Say (string name);
}
}

实现

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace aoptest
{
class MySay : ISay
{
public void Say(string name)
{
Console.WriteLine("fuck off" + name); }
}
}

通知 Advice

using System;
using AopAlliance.Intercept; namespace aoptest
{
public class MyInterceptor :IMethodInterceptor
{
public MyInterceptor ()
{
} public object Invoke(IMethodInvocation invocation)
{
Console.Out.WriteLine("zch before invoke method"); object result = invocation.Proceed(); Console.Out.WriteLine("zch after invoke method"); return result;
}
}
}

配置文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration> <configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring> <context>
<resource uri="config://spring/objects" />
</context> <objects xmlns='http://www.springframework.net'
xmlns:db="http://www.springframework.net/database"
xmlns:tx="http://www.springframework.net/tx"
default-autowire="byName" default-lazy-init="true"> <object id="aroundAdvice" type="aoptest.MyInterceptor" />
<object id="isay" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="Target">
<object id = "isayTarget" type="aoptest.MySay" />
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvice</value>
</list>
</property>
</object> </objects>
</spring>
</configuration>

调用


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spring.Context.Support;
using Spring.Context;
using Spring.Aop.Framework; namespace aoptest
{
class Program
{
static void Main (string[] args)
{
IApplicationContext ctx = ContextRegistry.GetContext();
ISay command = (ISay)ctx["isay"];
command.Say ("zch"); }
}
}

c# spring aop的简单例子的更多相关文章

  1. Spring Boot 2.X(八):Spring AOP 实现简单的日志切面

    AOP 1.什么是 AOP ? AOP 的全称为 Aspect Oriented Programming,译为面向切面编程,是通过预编译方式和运行期动态代理实现核心业务逻辑之外的横切行为的统一维护的一 ...

  2. java代理课程测试 spring AOP代理简单测试

    jjava加强课程测试代码 反射. 代理 .泛型.beanUtils等 项目源码下载:http://download.csdn.net/detail/liangrui1988/6568169 热身运动 ...

  3. 峰Spring4学习(6)spring AOP的应用例子

    一.AOP简介: 二.AOP实例: 三.使用的例子 需求:在student添加的前后,打印日志信息: 0)spring AOP需要引用的jar包: 1)StudentService.java接口: p ...

  4. Spring AOP配置简单记录(注解及xml配置方式)

    在了解spring aop中的关键字(如:连接点(JoinPoint).切入点(PointCut).切面(Aspact).织入(Weaving).通知(Advice).目标(Target)等)后进行了 ...

  5. spring aop expression简单说明

    <aop:config> <aop:pointcut id="userDAO" expression="execution(public * cn.da ...

  6. Spring AOP的简单示例

    配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://w ...

  7. spring 理解Spring AOP 一个简单的约定游戏

    应该说AOP原理是Spring技术中最难理解的一个部分,而这个约定游戏也许会给你很多的帮助,通过这个约定游戏,就可以理解Spring AOP的含义和实现方法,也能帮助读者更好地运用Spring AOP ...

  8. spring容器BeanFactory简单例子

    在Spring中,那些组成你应用程序的主体及由Spring Ioc容器所管理的对象,都被称之为bean.简单来讲,bean就是Spring容器的初始化.配置及管理的对象.除此之外,bean就与应用程序 ...

  9. (原创)Maven+Spring+CXF+Tomcat7 简单例子实现webservice

    这个例子需要建三个Maven项目,其中一个为父项目,另外两个为子项目 首先,建立父项目testParent,选择quickstart: 输入项目名称和模块名称,然后创建: 然后建立子项目testInt ...

随机推荐

  1. Qt之QHostInfo

    简述 QHostInfo 类为主机名查找提供了静态函数. QHostInfo 利用操作系统提供的查询机制来查询与特定主机名相关联的主机的 IP 地址,或者与一个IP地址相关联的主机名.这个类提供了两个 ...

  2. (转载)C语言 数组与指针的区别

    1) 字符串指针变量是个变量,指向字符串的首地址:而字符串数组名是个常量,为字符串数组第一个元素的地址: 2)字符串指针变量可以赋值,而字符串数组名不能赋值:对于字符数组只能对各个元素赋值,不能用以下 ...

  3. UVA 11383 Golden Tiger Claw 金虎爪(KM算法)

    题意: 给一个n*n的矩阵,每个格子中有正整数w[i][j],试为每行和每列分别确定一个数字row[i]和col[i],使得任意格子w[i][j]<=row[i]+col[j]恒成立.先输row ...

  4. Struts2的crud

    struts2的crud引出的问题: 1.当Action里面有其他类的实例引用属性时,当要用请求参数为该对象的属性赋值时,如何将其压入栈顶. 2.当有的操作(list)不需要创建该属性的实例对象时,或 ...

  5. 【解题报告】HDU -1142 A Walk Through the Forest

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1142 题目大意:Jimmy要从办公室走路回家,办公室在森林的一侧,家在另一侧,他每天要采取不一样的路线 ...

  6. HDFS命令行文件操作

    Hadoop文件操作命令形式为 hadoop fs -cmd <args> 说明:cmd是具体的文件操作命令,<args>是一组数目可变的参数. Hadoop最常用的文件操作命 ...

  7. python的subprocess无法进行通信(无法通过管道输入数据)的问题解决

    1.在主进程使用 p.stdin.write("something\n") 要有回车!要有回车!要有回车! 2.在子进程使用 data = raw_input() 读取数据,再用 ...

  8. freemaker转word xml注意事项

    java类字符串变量如果含有以下2种字符: &和  <,必须转义否则转化将失败. 其中: &替换成 & <替换成 < 因为一些怪字符数据库存储时已转义了,从数 ...

  9. Java正确转换html编码

    Java 中能將 html 編碼正確轉換的套件: org.apache.commons.lang.StringEscapeUtils. String source = "The less t ...

  10. C# GDI+学习笔记1

    —前言 本文是学习C# GDI+系列的第一篇文章,简单的介绍了GDI+的一些基本绘图内容,比较粗糙.但本文主要是让大家简单的回顾一下GDI+的基本概念.本篇文章的参考代码请在此下载 . GDIPTes ...