Sprinet.NET 学习笔记(2)-AOPQuickStart
2009-06-07 23:59
567 查看
1. Spring.AopQuickStart.Step1.2005 中使用new关键字进行AOP的实现
ProxyFactory factory = newProxyFactory(newServiceCommand());
factory.AddAdvice(newConsoleLoggingBeforeAdvice());
factory.AddAdvice(newConsoleLoggingAfterAdvice());
factory.AddAdvice(newConsoleLoggingThrowsAdvice());
ICommand command = (ICommand)factory.GetProxy();
command.Execute();
if (command.IsUndoCapable)
{
command.UnExecute();
}
2. Spring.AopQuickStart.Step2.2005 App.config配置进行AOP的实现
<spring>
<context>
<resource uri="config://spring/objects" />
</context>
<objects xmlns="http://www.springframework.net">
<description>相关描述</description>
<object id="aroundAdvice" type="Spring.AopQuickStart.Aspects.ConsoleLoggingAroundAdvice, Spring.AopQuickStart.Common" />
<object id="throwsAdvice" type="Spring.AopQuickStart.Aspects.ConsoleLoggingThrowsAdvice, Spring.AopQuickStart.Common" />
<object id="myServiceCommand" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="Target">
<object type="Spring.AopQuickStart.Commands.ServiceCommand, Spring.AopQuickStart.Common" />
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvice</value>
<value>throwsAdvice</value>
</list>
</property>
</object>
</objects>
</spring>
3. Spring.AopQuickStart.Step3.2005 通过配置NameMatchMethodPointcutAdvisor类使用名为MapperNames的属性进行拦截,从而匹配*Execute的方法所有方法的拦截
<spring>
<context>
<resource uri="config://spring/objects" />
</context>
<objects xmlns="http://www.springframework.net">
<description>相关描述</description>
<object id="aroundAdvisor" type="Spring.Aop.Support.NameMatchMethodPointcutAdvisor, Spring.Aop">
<property name="Advice">
<object type="Spring.AopQuickStart.Aspects.ConsoleLoggingAroundAdvice, Spring.AopQuickStart.Common" />
</property>
<property name="MappedNames">
<list>
<value>*Execute</value>
</list>
</property>
</object>
<object id="throwsAdvice" type="Spring.AopQuickStart.Aspects.ConsoleLoggingThrowsAdvice, Spring.AopQuickStart.Common" />
<object id="myServiceCommand" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="Target">
<object type="Spring.AopQuickStart.Commands.ServiceCommand, Spring.AopQuickStart.Common" />
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvisor</value>
<value>throwsAdvice</value>
</list>
</property>
</object>
</objects>
</spring>
4. Spring.AopQuickStart.Step5.2005通过配置NameMatchMethodPointcutAdvisor类使用名为Expression的属性进行拦截,下面为拦截方法返还类型为void,没有的参数的例子
<objects xmlns="http://www.springframework.net">
<description>相关描述</description>
<object id="aroundAdvisor"
type="Spring.AopQuickStart.Aspects.ExpressionDynamicPointcutAdvisor, Spring.AopQuickStart.Step5">
<property name="Advice">
<object type="Spring.AopQuickStart.Aspects.ConsoleLoggingAroundAdvice, Spring.AopQuickStart.Common" />
</property>
<property name="Expression" value="MethodInfo.ReturnType == T(System.Void) and Args != null" />
</object>
<object id="throwsAdvice"
type="Spring.AopQuickStart.Aspects.ConsoleLoggingThrowsAdvice, Spring.AopQuickStart.Common" />
<object id="myServiceCommand" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="Target">
<object type="Spring.AopQuickStart.Commands.ServiceCommand, Spring.AopQuickStart.Common" />
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvisor</value>
<value>throwsAdvice</value>
</list>
</property>
</object>
</objects>
5. Spring.AopQuickStart.Step5.2005 通过配置ObjectNameAutoProxyCreator类使用ObjectNames属性匹配*ServiceCommand进行拦截
<objects xmlns="http://www.springframework.net">
<description>相关描述</description>
<object id="myServiceCommand"
type="Spring.AopQuickStart.Commands.ServiceCommand, Spring.AopQuickStart.Common" />
<object id="myAnotherServiceCommand"
type="Spring.AopQuickStart.Commands.AnotherServiceCommand, Spring.AopQuickStart.Step7" />
<object id="aroundAdvisor" type="Spring.Aop.Support.NameMatchMethodPointcutAdvisor, Spring.Aop">
<property name="Advice">
<object type="Spring.AopQuickStart.Aspects.ConsoleLoggingAroundAdvice, Spring.AopQuickStart.Common" />
</property>
<property name="MappedNames">
<list>
<value>*Execute</value>
</list>
</property>
</object>
<object type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>*ServiceCommand</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvisor</value>
</list>
</property>
</object>
</objects>
其中QuickStart4和6没有整理好,好好学习之后再整理和大家分享。
ProxyFactory factory = newProxyFactory(newServiceCommand());
factory.AddAdvice(newConsoleLoggingBeforeAdvice());
factory.AddAdvice(newConsoleLoggingAfterAdvice());
factory.AddAdvice(newConsoleLoggingThrowsAdvice());
ICommand command = (ICommand)factory.GetProxy();
command.Execute();
if (command.IsUndoCapable)
{
command.UnExecute();
}
2. Spring.AopQuickStart.Step2.2005 App.config配置进行AOP的实现
<spring>
<context>
<resource uri="config://spring/objects" />
</context>
<objects xmlns="http://www.springframework.net">
<description>相关描述</description>
<object id="aroundAdvice" type="Spring.AopQuickStart.Aspects.ConsoleLoggingAroundAdvice, Spring.AopQuickStart.Common" />
<object id="throwsAdvice" type="Spring.AopQuickStart.Aspects.ConsoleLoggingThrowsAdvice, Spring.AopQuickStart.Common" />
<object id="myServiceCommand" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="Target">
<object type="Spring.AopQuickStart.Commands.ServiceCommand, Spring.AopQuickStart.Common" />
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvice</value>
<value>throwsAdvice</value>
</list>
</property>
</object>
</objects>
</spring>
3. Spring.AopQuickStart.Step3.2005 通过配置NameMatchMethodPointcutAdvisor类使用名为MapperNames的属性进行拦截,从而匹配*Execute的方法所有方法的拦截
<spring>
<context>
<resource uri="config://spring/objects" />
</context>
<objects xmlns="http://www.springframework.net">
<description>相关描述</description>
<object id="aroundAdvisor" type="Spring.Aop.Support.NameMatchMethodPointcutAdvisor, Spring.Aop">
<property name="Advice">
<object type="Spring.AopQuickStart.Aspects.ConsoleLoggingAroundAdvice, Spring.AopQuickStart.Common" />
</property>
<property name="MappedNames">
<list>
<value>*Execute</value>
</list>
</property>
</object>
<object id="throwsAdvice" type="Spring.AopQuickStart.Aspects.ConsoleLoggingThrowsAdvice, Spring.AopQuickStart.Common" />
<object id="myServiceCommand" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="Target">
<object type="Spring.AopQuickStart.Commands.ServiceCommand, Spring.AopQuickStart.Common" />
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvisor</value>
<value>throwsAdvice</value>
</list>
</property>
</object>
</objects>
</spring>
4. Spring.AopQuickStart.Step5.2005通过配置NameMatchMethodPointcutAdvisor类使用名为Expression的属性进行拦截,下面为拦截方法返还类型为void,没有的参数的例子
<objects xmlns="http://www.springframework.net">
<description>相关描述</description>
<object id="aroundAdvisor"
type="Spring.AopQuickStart.Aspects.ExpressionDynamicPointcutAdvisor, Spring.AopQuickStart.Step5">
<property name="Advice">
<object type="Spring.AopQuickStart.Aspects.ConsoleLoggingAroundAdvice, Spring.AopQuickStart.Common" />
</property>
<property name="Expression" value="MethodInfo.ReturnType == T(System.Void) and Args != null" />
</object>
<object id="throwsAdvice"
type="Spring.AopQuickStart.Aspects.ConsoleLoggingThrowsAdvice, Spring.AopQuickStart.Common" />
<object id="myServiceCommand" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="Target">
<object type="Spring.AopQuickStart.Commands.ServiceCommand, Spring.AopQuickStart.Common" />
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvisor</value>
<value>throwsAdvice</value>
</list>
</property>
</object>
</objects>
5. Spring.AopQuickStart.Step5.2005 通过配置ObjectNameAutoProxyCreator类使用ObjectNames属性匹配*ServiceCommand进行拦截
<objects xmlns="http://www.springframework.net">
<description>相关描述</description>
<object id="myServiceCommand"
type="Spring.AopQuickStart.Commands.ServiceCommand, Spring.AopQuickStart.Common" />
<object id="myAnotherServiceCommand"
type="Spring.AopQuickStart.Commands.AnotherServiceCommand, Spring.AopQuickStart.Step7" />
<object id="aroundAdvisor" type="Spring.Aop.Support.NameMatchMethodPointcutAdvisor, Spring.Aop">
<property name="Advice">
<object type="Spring.AopQuickStart.Aspects.ConsoleLoggingAroundAdvice, Spring.AopQuickStart.Common" />
</property>
<property name="MappedNames">
<list>
<value>*Execute</value>
</list>
</property>
</object>
<object type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>*ServiceCommand</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>aroundAdvisor</value>
</list>
</property>
</object>
</objects>
其中QuickStart4和6没有整理好,好好学习之后再整理和大家分享。
相关文章推荐
- Spring.NET学习笔记13——AOP的概念(基础篇) Level 200
- Spring.NET学习笔记13——AOP的概念(基础篇)
- tensorflow学习笔记十四:TF官方教程学习 tf.contrib.learn Quickstart
- Spring.NET学习笔记14——AOP的通知类型(基础篇)
- Spring.Net实现AOP以及AOP相关概念(学习笔记四)
- Unity学习笔记(一):StopLight QuickStart
- (7)学习笔记 ) ASP.NET CORE微服务 Micro-Service ---- 利用Polly+AOP+依赖注入封装的降级框架
- Zend framework quickstart 学习笔记
- spark学习笔记之quick-start
- TensorFlow学习笔记6----tf.contrib.learn Quickstart
- vue 学习笔记一之Quick Start
- Sprinet.NET 学习笔记(1)-MovieFinder
- spring.net 学习笔记之 AOP (异常记录实例)转
- 学习笔记:csv文件的读取和tf.contrib.learn Quickstart
- (6)学习笔记 ) ASP.NET CORE微服务 Micro-Service ---- AOP框架
- asp .net学习笔记之使用jmail发送邮件
- ASP.NET学习笔记一:Application,Server,Session对象
- asp.net实现页面的一般处理程序(CGI)学习笔记
- ASP.NET学习笔记:服务器控件 (2009.11.9)
- ASP.NET 2.0 之 Master Page 学习笔记