c# spring aop的简单例子
刚刚完成了一个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的简单例子的更多相关文章
- Spring Boot 2.X(八):Spring AOP 实现简单的日志切面
AOP 1.什么是 AOP ? AOP 的全称为 Aspect Oriented Programming,译为面向切面编程,是通过预编译方式和运行期动态代理实现核心业务逻辑之外的横切行为的统一维护的一 ...
- java代理课程测试 spring AOP代理简单测试
jjava加强课程测试代码 反射. 代理 .泛型.beanUtils等 项目源码下载:http://download.csdn.net/detail/liangrui1988/6568169 热身运动 ...
- 峰Spring4学习(6)spring AOP的应用例子
一.AOP简介: 二.AOP实例: 三.使用的例子 需求:在student添加的前后,打印日志信息: 0)spring AOP需要引用的jar包: 1)StudentService.java接口: p ...
- Spring AOP配置简单记录(注解及xml配置方式)
在了解spring aop中的关键字(如:连接点(JoinPoint).切入点(PointCut).切面(Aspact).织入(Weaving).通知(Advice).目标(Target)等)后进行了 ...
- spring aop expression简单说明
<aop:config> <aop:pointcut id="userDAO" expression="execution(public * cn.da ...
- Spring AOP的简单示例
配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://w ...
- spring 理解Spring AOP 一个简单的约定游戏
应该说AOP原理是Spring技术中最难理解的一个部分,而这个约定游戏也许会给你很多的帮助,通过这个约定游戏,就可以理解Spring AOP的含义和实现方法,也能帮助读者更好地运用Spring AOP ...
- spring容器BeanFactory简单例子
在Spring中,那些组成你应用程序的主体及由Spring Ioc容器所管理的对象,都被称之为bean.简单来讲,bean就是Spring容器的初始化.配置及管理的对象.除此之外,bean就与应用程序 ...
- (原创)Maven+Spring+CXF+Tomcat7 简单例子实现webservice
这个例子需要建三个Maven项目,其中一个为父项目,另外两个为子项目 首先,建立父项目testParent,选择quickstart: 输入项目名称和模块名称,然后创建: 然后建立子项目testInt ...
随机推荐
- IE下easyui 缓存问题
$.ajaxSetup ({ cache: false //关闭AJAX相应的缓存 }); 这一句话就足够了,很管用!
- JS 去除字符串中的空格
1. 去掉字符串前后所有空格: 代码如下: function Trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ""); } 说明: ...
- 51nod1394 差和问题
我只会用线段树写...不喜欢树状数组..其实跑的也不算慢?然后各种*的时候忘了longlong一直WA...药丸! 而且我不怎么会用map离散化...那么就sort+unique #include&l ...
- Java笔记之数组
1.int flags[] = new int[10];数组中的每个元素初始化为0. Arrays.fill(flags, 0);将数组中每个元素置为0.
- PS:WINRAR制作32位安装程序和64位安装程序选项
32位 64位
- notebook笔记
启动 __main__.py 静态文件 static/ 模板 templates/ 路由 比如tree/handlers.py default_handlers WebSocket ws://loca ...
- Linux/Unix shell 监控Oracle实例(monitor instance)
使用shell脚本实现对Oracle数据库的监控与管理将大大简化DBA的工作负担,如常见的对实例的监控,监听的监控,告警日志的监控,以及数据库的备份,AWR report的自动邮件等.本文给出Linu ...
- Android WebView中那些不得不解决的坑~~
前面那张hybrid开发心得 有人问 怎么解决不用onJsPrompt 来回调js函数的问题.其实很简单,就是在在你的jscalljava回调函数内 另外开个线程去load js代码即可: wb.po ...
- Java 中无参带返回值方法的使用
如果方法不包含参数,但有返回值,我们称为无参带返回值的方法. 例如:下面的代码,定义了一个方法名为 calSum ,无参数,但返回值为 int 类型的方法,执行的操作为计算两数之和,并返回结果 在 c ...
- php文件读写锁
$file = fopen("test.txt", $fileOpenMode); flock($file, $lockMode) or die("Can't lock& ...