aspectnet function Introduction (i)

Source: Internet
Author: User
Tags aop manual writing

Aspectnet is an aspect builder based on the. Net framework, which simultaneously enables static weaving and dynamic weaving, is a bobmazelin personal research project, and is still in the development phase, the introduction of AOP concepts please refer to: Www.aspectJ.org and IBM's project.

This is the first of Aspectnet feature introduction, I mainly introduce the basic structure of aspectnet in static knitting.

Aspectnet to a large extent reference to the ASPECTJ, it through the MSIL code to achieve static weaving, which aspectnet do not need source code, it can also be mixed weaving C # and VB.net (VC + +. NET can also be generated by the dynamic link library.

Aspectnet consists of aspect, each aspect can declare several pointcut,storage and advice.

The concept of 1.pointcut is basically consistent with the ASPECTJ, which captures the code points that need to be woven;

2.storage is a apsectnet-specific concept, similar to pointcut, capturing code that needs to be woven into pointcut;

The concept of 3.advice is basically consistent with ASPECTJ, but it does not need to write any C # or other code, it connects Pointcut and storage, enabling them to form many-to-many relational mappings.

Here's a simple example to illustrate these 3 concepts:

namespace Bob.Mazelin
{
  aspect Demo
  {
    pointcut AddDemo1():call(public void Mazelin.AspectNet.TestProject.TestClass.Demo1());
    before():AddDemo1():PrintBefore();

    after():AddDemo1():PrintAfter();

    storage PrintBefore():call(public void Mazelin.AspectNet.TestProject.PrintClass.PrintBefore());
    storage PrintAfter():call(public void Mazelin.AspectNet.TestProject.PrintClass.PrintAfter());  
  }
}

Where AddDemo1 is the name of Pointcut, which captures the Demo1 method, which has no return value and no parameters, It is all called the Mazelin.AspectNet.TestProject.TestClass class declaration. The call keyword indicates that the capture point is the point of the program that invokes the method;

Printbefore and Printafter are two storage types that capture the Printbefore and Printafter methods, which are similar in meaning to pointcut;

Before and after is advice, which connects AddDemo1 and Printbefore,printafter, so that Printbefore and Printafter are called before and after the ADDDEMO1 call respectively.

When the DLL and the aspect file that need to be woven are run together, a new code-woven DLL is generated. This kind of weaving approach does not affect the performance of the code, and is similar to the manual writing code, and dynamic weaving is better than performance, but lack of flexibility.

Let's get here today, and next time I'll introduce the use of call and execution pointcut in Aspectnet, and ask for more valuable advice from friends who are interested in AOP.

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.