引用Microsoft.Practices.Unity.InterceptionExtension,AOP面向方面编写

1.定义

 1 using System;
 2 using Microsoft.Practices.Unity;
 3 using Microsoft.Practices.Unity.InterceptionExtension;
 4 
 5 namespace InteceptionExtension
 6 {
 7     public class FooCallHandler : ICallHandler
 8     {
 9         public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
10         {
11             Console.WriteLine("Foo: Preoperation is executed.");
12             var methodReturn = getNext()(input, getNext);
13             Console.WriteLine("Foo: Postoperation is executed.");
14             return methodReturn;
15         }
16         public int Order { get; set; }
17     }    
18 
19     public class FooCallHandlerAttribute : HandlerAttribute
20     {
21         public override ICallHandler CreateHandler(IUnityContainer container)
22         {
23             return new FooCallHandler { Order = this.Order };
24         }
25     }   
26 }
View Code

1.引用

1 [FooCallHandler]
2     public interface IBar
3     {
4         void DoSomething();
5     }
View Code

 

posted @ 2014-07-15 10:09  bert.zeng  阅读(420)  评论(0编辑  收藏  举报