来源:
http://www.cnblogs.com/leao/archive/2005/09/29/246819.html
如下是使用定义了的Spring上下文对象来实现Aop的功能(摘自Aop Quick Start)。第1-3行取得上下文对象,该对象可替代真正的业务逻辑对象ServcieCommand。
至此,我们可以看到Spring.Net的Aop实现是“工厂方法+面向接口编程+×××”,这个×××的技术核心就是myServiceObject上下文对象(即代码中的command对象)是如何构造出来的,它自动实现ServiceCommand的实现接口ICommand接口。我尝试使用 Visual Studio .Net 2003的监控功能,却无法获得command的任何对象信息。
针对接口编程使得,程序员不得不遵循接口的编程方式。一来比较死板,二来旧的代码服用率降低。希望Spring.Net能提供类似JBoss的基于class load的Aop实现。
http://www.cnblogs.com/leao/archive/2005/09/29/246819.html
日志、异常、权限,这些几乎在所有的框架或者工程中都会不可避免的底层功能,对于程序员来说是枯燥无聊的简单重复的编写代码行。但是当我第一次听说AOP编程概念的时候,我就隐约感觉到程序员从此可以从那些非业务逻辑的代码行编写中解放出来。
粗略看了一下Spring.Net的Aop QuickStart,演示了简单的横切功能。如下是App.Config文件中Sprint.Net的配置信息。第9-22行,定义了一个名为 "myServiceObject"的Sprint.Net上下文对象,该对象服务于是target对象 "myServiceObjectTarget",并且提供名为"consoleLoggingAroundAdvice"的服务(该服务由上面定义的同名对象提供)。
1
<objects xmlns="http://www.springframework.net">
2
<description>An example that demonstrates simple AOP functionality.</description>
3
<object id="consoleLoggingAroundAdvice" type="Spring.Aop.Support.RegexpMethodPointcutAdvisor">
4
<property name="pattern" value="Do"/>
5
<property name="advice">
6
<object type="Spring.Examples.AopQuickStart.ConsoleLoggingAroundAdvice"/>
7
</property>
8
</object>
9
<object
10
id="myServiceObject"
11
type="Spring.Aop.Framework.ProxyFactoryObject">
12
<property name="target">
13
<object
14
id="myServiceObjectTarget"
15
type="Spring.Examples.AopQuickStart.ServiceCommand"/>
16
</property>
17
<property name="interceptorNames">
18
<list>
19
<value>consoleLoggingAroundAdvice</value>
20
</list>
21
</property>
22
</object>
23
</objects>
24![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
如下是使用定义了的Spring上下文对象来实现Aop的功能(摘自Aop Quick Start)。第1-3行取得上下文对象,该对象可替代真正的业务逻辑对象ServcieCommand。
1
IApplicationContext ctx
2
= ConfigurationSettings.GetConfig("spring/context") as IApplicationContext;
3
ICommand command = (ICommand) ctx["myServiceObject"];
4
command.Execute();
5![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
至此,我们可以看到Spring.Net的Aop实现是“工厂方法+面向接口编程+×××”,这个×××的技术核心就是myServiceObject上下文对象(即代码中的command对象)是如何构造出来的,它自动实现ServiceCommand的实现接口ICommand接口。我尝试使用 Visual Studio .Net 2003的监控功能,却无法获得command的任何对象信息。
针对接口编程使得,程序员不得不遵循接口的编程方式。一来比较死板,二来旧的代码服用率降低。希望Spring.Net能提供类似JBoss的基于class load的Aop实现。