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 ...
随机推荐
- IIS HTTPS 禁用不安全的SSL2.0
禁用: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\Schannel\Protocols 验证:
- SpiderMonkey的使用
基于 C 语言的 JavaScript 引擎探索 http://www.ibm.com/developerworks/cn/linux/l-cn-spidermonkey/ https://devel ...
- Redis五大数据结构
1.Redis介绍 Redis是REmote DIctionary Server的缩写,作者定位于一个内存KV存储数据库(In-memory key-value Store),让Redis自豪的并不是 ...
- 【BZOJ】【1923】【Sdoi2010】外星千足虫
高斯消元解Xor方程组 ZYF Orz 这题……不作死就不会死T^T,用bitset确实比较快,而且可以从string直接转成bitset(构造函数). 但问题是我把转过来以后的顺序搞反了……原本以为 ...
- iOS:制作九宫格
制作简单的九宫格: 源码如下: #import "ViewController.h" @interface ViewController () @end @implementati ...
- trapping-rain-water-ii
https://leetcode.com/problems/trapping-rain-water-ii/ // https://discuss.leetcode.com/topic/60418/ja ...
- 【Dagger2】 案例大全
只有Inject是不可以的,必须有Component public class Test { @Inject Person person; private void test() { System.o ...
- 火速提升Android仿真器的运行速度 ——仿真器Genymotion
一.问题概述 Android开发中会使用仿真器测试应用,但不管你使用Eclispe ADT还是Android Studio仿真器都是基于arm架构的,运行起来都很慢,光启动就要花费很多时间,都不知道它 ...
- 关于NLPIR应用在KETTLE中的探索
一:什么是NLPIR? NLPIR汉语分词系统(自然语言处理与信息检索共享平台),主要功能包括中文分词:词性标注:命名实体识别:用户词典功能:支持GBK编码.UTF8编码.BIG5编码.新增微博分词. ...
- CPC广告反作弊
原文:http://blog.csdn.net/xwm1000/article/details/45460957 CPC广告上线也2年了,从上线以来就一直存在着作弊和反作弊的斗争,刚开始的时候流量少, ...