1.定义
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
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 }
1.引用
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 [FooCallHandler] 2 public interface IBar 3 { 4 void DoSomething(); 5 }