spring.net aop 讲解
spring.net aop几个术语:
切面:针对类
切点:针对方法
object.xml
- <?xml version="1.0" encoding="utf-8" ?>
- <objects xmlns="http://www.springframework.net" xmlns:aop="http://www.springframework.net/aop">
- <object id="user" type="TestAop.User" ></object>
- <object id="newUser" type="TestAop.NewUser" ></object>
- <object id="advisor" type="TestAop.Advisor"></object>
- <aop:config>
- <aop:advisor pointcut-ref="pointcut" advice-ref="advisor"/>
- </aop:config>
- <object id="pointcut" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop">
- <property name="pattern" value="TestAop.User.Whoami"/>
- </object>
- </objects>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace TestAop
- {
- public class Advisor : AopAlliance.Intercept.IMethodInterceptor
- {
- public object Invoke(AopAlliance.Intercept.IMethodInvocation invocation)
- {
- NewUser newUser = new NewUser();
- newUser.BeforeWhoami();
- var result = invocation.Proceed();
- newUser.AfterWhoami();
- return result;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace TestAop
- {
- public class NewUser
- {
- public void BeforeWhoami()
- {
- Console.WriteLine("I am before");
- }
- public void AfterWhoami()
- {
- Console.WriteLine("I am after");
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace TestAop
- {
- public interface IUser
- {
- void Whoami();
- }
- public class User:IUser
- {
- public void Whoami()
- {
- Console.WriteLine("I am zhangwei");
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace TestAop
- {
- class Program
- {
- static void Main(string[] args)
- {
- Spring.Context.IApplicationContext context
- = new Spring.Context.Support.XmlApplicationContext("objects.xml");
- IUser user = context.GetObject("user") as IUser;
- user.Whoami();
- Console.ReadKey();
- }
- }
- }
运行:
spring.net aop 讲解的更多相关文章
- Spring框架(4)---AOP讲解铺垫
AOP讲解铺垫 不得不说,刚开始去理解这个Aop是有点难理解的,主要还是新的概念比较多,对于初学者一下子不一定马上能够快速吸收,所以我先对什么事Aop做一个解释: 首先说明:本文不是自己所写 ...
- Spring基于AOP的事务管理
Spring基于AOP的事务管理 事务 事务是一系列动作,这一系列动作综合在一起组成一个完整的工作单元,如果有任何一个动作执行失败,那么事务 ...
- spring的AOP
最近公司项目中需要添加一个日志记录功能,就是可以清楚的看到谁在什么时间做了什么事情,因为项目已经运行很长时间,这个最初没有开来进来,所以就用spring的面向切面编程来实现这个功能.在做的时候对spr ...
- spring(二) AOP之AspectJ框架的使用
前面讲解了spring的特性之一,IOC(控制反转),因为有了IOC,所以我们都不需要自己new对象了,想要什么,spring就给什么.而今天要学习spring的第二个重点,AOP.一篇讲解不完,所以 ...
- Spring中AOP简介与切面编程的使用
Spring中AOP简介与使用 什么是AOP? Aspect Oriented Programming(AOP),多译作 "面向切面编程",也就是说,对一段程序,从侧面插入,进行操 ...
- 02 浅析Spring的AOP(面向切面编程)
1.关于AOP AOP(Aspect Oriented Programming),即面向切面编程,可以说是OOP(Object Oriented Programming,面向对象编程)的补充和完善.O ...
- Spring【AOP模块】就是这么简单
前言 到目前为止,已经简单学习了Spring的Core模块.....于是我们就开启了Spring的AOP模块了...在讲解AOP模块之前,首先我们来讲解一下cglib代理.以及怎么手动实现AOP编程 ...
- Spring基础篇——Spring的AOP切面编程
一 基本理解 AOP,面向切面编程,作为Spring的核心思想之一,度娘上有太多的教程啊.解释啊,但博主还是要自己按照自己的思路和理解再来阐释一下.原因很简单,别人的思想终究是别人的,自己的理解才是 ...
- spring框架 AOP核心详解
AOP称为面向切面编程,在程序开发中主要用来解决一些系统层面上的问题,比如日志,事务,权限等待,Struts2的拦截器设计就是基于AOP的思想,是个比较经典的例子. 一 AOP的基本概念 (1)Asp ...
随机推荐
- 基于非比較的排序:计数排序(countSort),桶排序(bucketSort),基数排序(radixSort)
计数排序 条件:要排序的数组的元素必须是在一定范围的,比方是1~100.在排序之前我们必须知道数组元素的范围. 思路:顾名思义:就是用一个数组来计数的. 步骤: 1.用一个数组来计数count[ ], ...
- [翻译] EnterTheMatrix
Enter The Matrix https://github.com/mpospese/EnterTheMatrix The sample application to accompany my c ...
- 求助关于jquery easyUI中的treegrid组件,请各位帮忙给个思路,谢谢啦
现在项目中用到jquery easyUI中的treegrid组件,已经可以正常显示了.但是在保存的时候遇到问题,页面上参照官网的例子可以在页面更新,但是怎么获取编辑后的数据进而保存到数据库呢?
- [Android Pro] activity-alias的使用
activity-alias是android里为了重复使用Activity而设计的. 当在Activity的onCreate()方法里,执行getIntent().getComponent().get ...
- 常用的OpenCV函数速查
常用的OpenCV函数速查 1.cvLoadImage:将图像文件加载至内存: 2.cvNamedWindow:在屏幕上创建一个窗口: 3.cvShowImage:在一个已创建好的窗口中显示图像: 4 ...
- OBjective-C:文件管理类NSFileManager
文件管理类NSFileManager类:对文件进行创建.复制.重命名.删除等,一般不对文件内容进行操作. NSData类和NSMutableData类:相当于数据缓冲区 NSFileManager是 ...
- strtok()函数
strtok()这个函数大家都应该碰到过,但好像总有些问题, 这里着重讲下它 首先看下MSDN上的解释: char *strtok( char *strToken, const char *strDe ...
- Container With Most Water leetcode java
题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...
- css美化、优化、合并工具推荐
其实很多时候,我们写完css规则之后,我们思考的无非就是3件事情: 验证 美化 压缩 当然无论是我们自己做这样的工具还是寻找一些比较好的成熟的工具,都有几个期望: 是否支持一些ie下的hack方式: ...
- 解决在ubuntu 12.10安装vmware-tools实现文件共享问题
解决在ubuntu 12.10安装vmware-tools出现的“The path "" is not a valid path to linux-headers-3.5.0-17 ...