10-minute getting started with AOP: popularize AOP with postsharp

Source: Internet
Author: User
Postsharp is an easy-to-learn and easy-to-use AOP framework. Before that, I used aspectj and spring. of course, it takes a little time, but I still feel that it is difficult to master. It seems that AOP is a relatively difficult thing. The description in this English paper does not seem so difficult to grasp. For more information, see.


PS uses what we are familiar with without introducing new terms. This is a wise place for PS. Look at a group of concepts on the right of the table, events (which are not quite understood why Meta is used), event processor, aspect = custom attribute, and the only new one is multicasting, it can be understood as a wildcard expression.

The following is a simple example:

Public   Class Logattribute: onmethodboundaryaspect
{
Public   Override   Void Onentry (methodexecutioneventargs eventargs)
{Console. writeline ("Entering the Method{0}.", Eventargs. method );
}
Public   Override   Void Onexit (methodexecutioneventargs eventargs)
{
Console. writeline ("Leaving the Method{0}.", Eventargs. method );
}
}
class Program
{< br> [log]
static void main ()
{< br> console. writeline ("Hello, world. ");
}< BR >}< P>

// multicasting indicates that MyApp. use log in the businessobjects namespace

[assembly: log (
attributetargettypes =
"MyApp. businessobjects. * ",
attributetargetmembe Rattributes =
multicastattributes. Public)]

the example is concise, clear, and easy to learn.

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.