An Implementation of AOP static crosscutting

Source: Internet
Author: User
There are already too many dynamic interception methods for AOP. Article But there are few implementations of static cross-cutting. Therefore, I would like to provide an implementation idea for the purpose of launching a discussion.
The main idea of implementation is as follows:
The Source code Write a file (for example, log. aspect), and then intercept the new operator (this can be referred to other people's articles, and use proxyattribute to inherit from marshalbyrefobject) or use the factory mode during construction, and return the inheritance class of the object to be generated, here, I use a temporary source file and dynamic compilation in codedom. Basically temporary files Code As follows:

Public   Class Aop_target: Target
{
//Insert the code to weave-in (read from *. aspect), for example:
//Public void log (string MSG)
//{
//
//}
}

This implementation is relatively simple, but the efficiency must be relatively poor. I believe that using emit will greatly improve.

Finally, the weave-in method can only be called Using Reflection and invoke. This is probably a big weakness, but on the premise that the C # compiler is fully used, this is probably the only way to do this.

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.