Core Components in my heart (Pluggable AOP )~ Forth exception interceptor

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.