成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

C#實(shí)現(xiàn)AOP微型框架深入剖析

開發(fā) 后端
這里介紹C#實(shí)現(xiàn)AOP微型框架,AOP的最基本功能就是實(shí)現(xiàn)特定的預(yù)處理和后處理,我通過代理讓C#實(shí)現(xiàn)AOP微型框架。先來看看構(gòu)成此微型框架的.cs文件。

在向大家詳細(xì)介紹C#實(shí)現(xiàn)AOP微型框架之前,首先讓大家了解下微型框架的.cs文件,然后全面介紹C#實(shí)現(xiàn)AOP微型框架。

在前面的系列文章中,我介紹了消息、代理與AOP的關(guān)系,這次將我自己用C#實(shí)現(xiàn)AOP微型框架拿出來和大家交流一下。

AOP的最基本功能就是實(shí)現(xiàn)特定的預(yù)處理和后處理,我通過代理讓C#實(shí)現(xiàn)AOP微型框架。先來看看構(gòu)成此微型框架的.cs文件。

1.CommonDef.cs 用于定義最基本的AOP接口

  1. using System;  
  2. using System.Runtime.Remoting.Messaging ;  
  3.  
  4. namespace EnterpriseServerBase.Aop  
  5. {  
  6. /// <summary> 
  7. /// IAopOperator AOP操作符接口,包括前處理和后處理  
  8. /// 2005.04.12  
  9. /// </summary> 
  10. public interface IAopOperator  
  11. {  
  12. void PreProcess(IMessage requestMsg ) ;  
  13. void PostProcess(IMessage requestMsg ,IMessage Respond) ;  
  14. }  
  15.  
  16. /// <summary> 
  17. /// IAopProxyFactory 用于創(chuàng)建特定的Aop代理的實(shí)例,
    IAopProxyFactory的作用是使AopProxyAttribute獨(dú)立于具體的AOP代理類。  
  18. /// </summary> 
  19. public interface IAopProxyFactory  
  20. {  
  21. AopProxyBase CreateAopProxyInstance(MarshalByRefObject obj ,Type type) ;  
  22. }  
  23.  

2. AopProxyBase AOP代理的基類

所有自定義AOP代理類都從此類派生,覆寫IAopOperator接口,實(shí)現(xiàn)具體的前/后處理 。

  1. using System;  
  2. using System.Runtime.Remoting ;  
  3. using System.Runtime.Remoting.Proxies ;  
  4. using System.Runtime.Remoting.Messaging ;  
  5. using System.Runtime.Remoting.Services ;  
  6. using System.Runtime.Remoting.Activation ;  
  7.  
  8. namespace EnterpriseServerBase.Aop  
  9. {  
  10. /// <summary> 
  11. /// AopProxyBase 所有自定義AOP代理類都從此類派生,
    覆寫IAopOperator接口,實(shí)現(xiàn)具體的前/后處理 。  
  12. /// 2005.04.12  
  13. /// </summary> 
  14. public abstract class AopProxyBase : RealProxy ,IAopOperator  
  15. {  
  16. private readonly MarshalByRefObject target ; //默認(rèn)透明代理  
  17.  
  18. public AopProxyBase(MarshalByRefObject obj ,Type type) :base(type)  
  19. {  
  20. this.target = obj ;  
  21. }  
  22.  
  23. #region Invoke  
  24. public override IMessage Invoke(IMessage msg)  
  25. {  
  26. bool useAspect = false ;  
  27. IMethodCallMessage call = (IMethodCallMessage)msg ;  
  28.  
  29. //查詢目標(biāo)方法是否使用了啟用AOP的MethodAopSwitcherAttribute  
  30. foreach(Attribute attr in call.MethodBase.GetCustomAttributes(false))  
  31. {  
  32. MethodAopSwitcherAttribute mehodAopAttr = attr as MethodAopSwitcherAttribute ;  
  33. if(mehodAopAttr != null)  
  34. {  
  35. if(mehodAopAttr.UseAspect)  
  36. {  
  37. useAspect = true ;  
  38. break ;  
  39. }  
  40. }  
  41. }  
  42.  
  43. if(useAspect)  
  44. {  
  45. this.PreProcess(msg) ;  
  46. }  
  47.  
  48. //如果觸發(fā)的是構(gòu)造函數(shù),此時(shí)target的構(gòu)建還未開始  
  49. IConstructionCallMessage ctor = call as IConstructionCallMessage ;  
  50. if(ctor != null)  
  51. {  
  52. //獲取***層的默認(rèn)真實(shí)代理  
  53. RealProxy default_proxy = RemotingServices.GetRealProxy(this.target) ;  
  54.  
  55. default_proxy.InitializeServerObject(ctor) ;  
  56. MarshalByRefObject tp = (MarshalByRefObject)this.GetTransparentProxy() ; 
  57. //自定義的透明代理 this  
  58.  
  59. return EnterpriseServicesHelper.CreateConstructionReturnMessage(ctor,tp);  
  60. }  
  61.  
  62. IMethodReturnMessage result_msg = RemotingServices.ExecuteMessage(this.target ,call) ; 
  63. //將消息轉(zhuǎn)化為堆棧,并執(zhí)行目標(biāo)方法,方法完成后,再將堆棧轉(zhuǎn)化為消息  
  64.  
  65. if(useAspect)  
  66. {  
  67. this.PostProcess(msg ,result_msg) ;  
  68. }  
  69.  
  70. return result_msg ;  
  71.  
  72. }  
  73. #endregion  
  74.  
  75. #region IAopOperator 成員  
  76.  
  77. public abstract void PreProcess(IMessage requestMsg) ;  
  78. public abstract void PostProcess(IMessage requestMsg, IMessage Respond) ;  
  79. #endregion  
  80. }  

【編輯推薦】

  1. C#創(chuàng)建表單簡單介紹
  2. C#修改DataReader默認(rèn)行為
  3. C#設(shè)置CooperativeLevel概述
  4. C#表單增加控件簡單描述
  5. C# EmployeePlug類概述
責(zé)任編輯:佚名 來源: 博客園
相關(guān)推薦

2009-09-03 15:38:54

C#實(shí)現(xiàn)AOP微型框架

2009-09-02 13:36:58

C#實(shí)現(xiàn)多個(gè)接口

2009-09-02 18:14:33

C# WebClien

2009-09-11 11:09:36

C#引用類型

2009-09-04 17:56:22

C#刪除數(shù)據(jù)

2009-09-03 17:42:07

C#開發(fā)CF藍(lán)牙模塊

2009-09-29 10:00:40

Spring AOP框

2009-09-04 17:49:34

C#連接數(shù)據(jù)庫

2015-07-28 10:06:03

C#內(nèi)部實(shí)現(xiàn)剖析

2009-09-10 17:37:01

C# get post

2009-08-28 15:38:49

C#實(shí)現(xiàn)斷點(diǎn)續(xù)傳

2009-08-27 17:14:36

C# Socket

2009-09-07 14:29:52

C# ServiceC

2009-09-01 16:29:03

QuickSort C

2024-12-16 00:50:56

2010-02-06 16:05:51

C++ Vector

2009-09-01 11:04:59

C#調(diào)用擴(kuò)展方法

2009-08-27 16:29:18

C#動(dòng)態(tài)編譯

2009-09-11 11:17:04

C#引用類型

2009-08-27 17:51:34

C#匿名方法
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 中文字幕日韩欧美一区二区三区 | 国产成人精品一区二区在线 | 久久aⅴ乱码一区二区三区 亚洲欧美综合精品另类天天更新 | 99久久婷婷国产综合精品电影 | tube国产| 在线第一页 | 久久国产精品偷 | 亚洲精品一区久久久久久 | 欧美国产日韩精品 | 中文字幕一区在线 | 亚洲欧美一区二区三区国产精品 | 久久不卡 | 欧美在线观看一区 | 国产不卡一 | 成人在线精品视频 | 日韩一区二区三区在线 | 午夜视频免费在线 | a级黄色片在线观看 | 超碰最新在线 | 天天拍天天操 | 夜夜夜久久久 | 国产毛片毛片 | 综合久久久久 | 免费黄色日本 | 欧美亚洲另类丝袜综合网动图 | 欧美亚洲国产成人 | 中文字幕在线观看一区 | 国产精品色哟哟网站 | 国产一区二区成人 | 国产一区二区三区四区三区四 | 国产亚洲精品成人av久久ww | 97操操 | 亚洲精品国产成人 | 精品在线一区 | 一级毛毛片 | 黄色成人亚洲 | 99这里只有精品视频 | 日韩在线小视频 | 国产精品日本一区二区在线播放 | 欧美日韩综合一区 | 久久国产精品久久国产精品 |