缘起
    为了在我的《朗志轻量级项目管理解决方案》项目中应用AOP,考虑了多种实现方式,首先想到的是postsharp,无奈它是基于2.0的,要不然它是首选了,可惜我的项目是基于1.1,只好舍弃了。接下来就是Castle DynamicProxy,可是它需要虚的非密封方法,这个要求让我很为难,也只好放弃了。最后选择了Remoting的实现方式,虽然它有百般的不是,但是对于我的这个项目而言,最重要的是可以解决我的问题,而且项目对性能效率几乎可以说是没有要求,查看了一下园子里关于使用Remoting实现aop的文章,那可不是一般的多哈,而且都贴出了相应的实现代码(注意是个“贴”字)可对于我这样的懒人,连粘代码调试的心情都没有。几经波折,发现了孙亚民先生的WebSharp这个东东,里面包含了一个基于Remoting的Aspect模块,对其做了良好的包装,而且说明的文档详尽,还是中文的,于是就在项目中使用它了。

问题
在WebSharp中提供了拦截类方式,如下

对websharp中aspect的改进(待续)<?xml version="1.0" encoding="utf-8" ?>
对websharp中aspect的改进(待续)
<configuration>
对websharp中aspect的改进(待续)    
<configSections>
对websharp中aspect的改进(待续)
<section name="Websharp.Aspects" type="Websharp.Aspect.AspectConfigHandler,Websharp.Aspect" />
对websharp中aspect的改进(待续)    
</configSections>
对websharp中aspect的改进(待续)    
对websharp中aspect的改进(待续)    
<Websharp.Aspects>
对websharp中aspect的改进(待续)        
<Aspect type="WeaveTest.FirstAspect,WeaveTest" deploy-model="None" 
对websharp中aspect的改进(待续) pointcut-type
="Method|Construction|Property" action-position="Both" match="*,Get*" />
对websharp中aspect的改进(待续)    
</Websharp.Aspects>
对websharp中aspect的改进(待续)
</configuration>
对websharp中aspect的改进(待续)


注意黄色的部分,就是原先的匹配方式,我想对项目中的一类方法进行横切,但是其中有几个是特例,再是我的方法的命名又没有什么规则,万般无奈之下动了改造的念头,我设想的是能够达到如下的效果

对websharp中aspect的改进(待续)    <Langzhi.Aspects>
对websharp中aspect的改进(待续)        
<Aspect type="Langzhi.Security.Aspect.PermissionAspect,Langzhi.Security" deploy-model="Singleton" pointcut-type="Method" action-position="Before">
对websharp中aspect的改进(待续)            
<Rule type="include" match="Langzhi\.PM\.BLL\.Facade\..*,.*" />
对websharp中aspect的改进(待续)            
<Rule type="exclude" match="Langzhi\.PM\.BLL\.Facade\.UserManager,ValidLogin" />
对websharp中aspect的改进(待续)        
</Aspect>
对websharp中aspect的改进(待续)        
<Aspect type="Langzhi.Security.Aspect.AuditLogAspect,Langzhi.Security" deploy-model="Singleton"    pointcut-type="Method" action-position="After">
对websharp中aspect的改进(待续)            
<Rule type="include" match="Langzhi\.PM\.BLL\.Facade\..*,.*" />
对websharp中aspect的改进(待续)            
<Rule type="exclude" match="Langzhi\.PM\.BLL\.Facade\.UserManager,ValidLogin" />
对websharp中aspect的改进(待续)        
</Aspect>
对websharp中aspect的改进(待续)        
<Aspect type="Langzhi.Security.Aspect.LoginAuditLogAspect,Langzhi.Security" deploy-model="Singleton" pointcut-type="Method" action-position="Both">
对websharp中aspect的改进(待续)            
<Rule type="include" match="Langzhi\.PM\.BLL\.Facade\.UserManager,ValidLogin" />
对websharp中aspect的改进(待续)        
</Aspect>
对websharp中aspect的改进(待续)        
<Aspect type="Langzhi.Security.Aspect.LogoutAuditLogAspect,Langzhi.Security" deploy-model="Singleton" pointcut-type="Method" action-position="Both">
对websharp中aspect的改进(待续)            
<Rule type="include" match="Langzhi\.PM\.BLL\.Facade\.UserManager,Logout" />
对websharp中aspect的改进(待续)        
</Aspect>
对websharp中aspect的改进(待续)    
</Langzhi.Aspects>

改造
}

配置文件变了,当然,读取的方式也得变了,原先WebSharp Aspect中采用的是操作xml的方式来读取节点,这里我们使用了反串行化的方式,还原对象的状态。这或许是一点小小的进步吧,但不知道效率怎么样了,不故用起来倒是挺爽的。

__________________________________________
朗志工作室:承接北京地区网站类项目

相关文章:

  • 2022-12-23
  • 2022-02-07
  • 2022-01-22
  • 2022-01-04
  • 2021-07-13
  • 2022-01-24
  • 2021-06-08
  • 2021-10-20
猜你喜欢
  • 2021-12-19
  • 2021-05-26
  • 2021-09-21
  • 2022-12-23
  • 2022-01-24
  • 2021-05-20
  • 2021-09-07
相关资源
相似解决方案