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 ...
随机推荐
- kafka存储机制
kafka存储机制 @(博客文章)[storm|大数据] kafka存储机制 一关键术语 二topic中partition存储分布 三 partiton中文件存储方式 四 partiton中segme ...
- C语言:返回两个数组中第一个元素的指针,并输出这个值
// // main.c // Pointer_search // // Created by ma c on 15/8/2. // Copyright (c) 2015年. All righ ...
- 第十二章 springboot + mongodb(复杂查询)
简单查询:使用自定义的XxxRepository接口即可.(见 第十一章 springboot + mongodb(简单查询)) 复杂查询:使用MongoTemplate以及一些查询条件构建类(Bas ...
- Hello World with Ant
都说Linux环境下的程序员如果不会使用GNU make来构建和管理自己的工程,应该不能算是一个合格的专业程序员,至少不能称得上是Unix程序员. 而在一说到Ant的时候,很多人就把这两个的功能对比来 ...
- .NET反射 Type类
不知道大家有过这样类似的编码 ? 1 Type type=typeof(T);//T是传入的类型 这样写已经是在潜意思的使用反射了.不管你是否知道,但是这是事实. Type是一个抽象类,必须进行实例化 ...
- java线上服务问题排查
1.业务日志相关 假设系统出现异常或者业务有异常,首先想到的都是查看业务日志 查看日志工具: less 或者more grep tail -f filename 查看实时的最新内容 ps:切忌vim直 ...
- .7z.001,.7z.002这样的文件如何解压
1 如图所示,压缩分卷没有显示关联的软件来打开,Winrar右击也无法解压 2 可以使用7-ZIP软件打开该文件,然后选择提取(相当于Winrar的解压),然后选择提取路径,默认是同一个文件夹,点击确 ...
- springboot项目打包提示Unable to find a single main class from the following candidates错误
提示Unable to find a single main class from the following candidates错误的原因是会从所有代码里面扫描包括main方法的类,找到多个类就报 ...
- wepy - 入手
wepy官方文档: https://tencent.github.io/wepy/document.html#/ ESLint:一般用来校验JavaScript代码是否符合规范,不符合预期就报错(程序 ...
- Linux一些基本命令一(学习笔记三)
菜鸟记录. 一.更改主机名 hostname 新的主机名 hostname ln0491 将主机名更改为ln0491 登出再登陆,就变为新的主机名 二.新建文件夹和删除 如:在当前路径新建data文件 ...