Back to directory
I have mentioned earlier articles about interceptor and the second back-to-Cache interceptor. In fact, the most mentioned here is the AOP and cache components. I have no detailed description of the interception concept, this talk, not about AOP, mainly about interceptor and Interception. It is mainly about Dynamically adding some actions before or after method execution, and this behavior mainly includes cache, log, exception Handling and everything you can think.
This is an exception Interceptor. Its main significance is that when a method is executed, you can use the configuration file to manage whether a unified Exception Handling action is attached before and after the method is executed.
We still use Unity. InterceptionExtension as the interceptor component. It depends on Unity. When Unity is not installed, Unity. InterceptionExtension will help you add it by yourself. This is correct.
The IInterceptionBehavior interface must be implemented for the interceptor we developed. This is the content of the interface.
WillExecute {IEnumerable <Type>View Code
Among them, the Invoke method is the method to be executed before the interception method. When the target method is implemented, it first checks whether the information of this method is available. If yes, it intercepts the behavior, in this example, abnormal interception is performed.
Exception interceptor code:
IInterceptionBehavior Members IEnumerable<Type> methodReturn = (methodReturn.Exception != {
To enable the Interceptor to work, we can configure it in the configuration file. The following is the configuration code for cache interception and exception interception. They are affiliated to the Unity node.
<! -- BEGIN: Unity --> <unity xmlns => <sectionExtension type =/> <container> <extension type =/> <register type = mapTo =/> <! -- Inject data context --> <register type = mapTo =/> <! -- Inject and cache access to WCF and intercept exceptions --> <register type = mapTo => <! -- <Interceptor type =/> --> <interceptor type =/> <interceptionBehavior type =/> </register> </container> </unity> <! -- END: Unity -->
How do you know and understand the interceptor!
Back to directory