Library tutorials & articles

Aspect Oriented Programming using .NET

What is AOP?

Aspect Oriented Programming or AOP is an interesting concept that can be applied to many of the programming problems we solve everyday. In our Visual Studio team system code we have a lot of web-services and remoting code that essentially does the following

public void MyMethod(int parameter)
{
Trace.EnteredMethod("MyMethod", parameter);
SecurityCheck();
// Bunch of processing
Trace.ExitMethod("MyMethod");
}

This is not just peculiar to our domain but is seen across different domains. In OO programming classes and methods are designed for performing specific operations and common/duplicate functionality are factored out into common classes. However, there are cross-cutting concerns that span accross all classes and methods, like logging and security checks. OOP only partially solves this problem by requiring users to define separate classes for logging and security checks and requiring each class/methods needing these services to call them. AOP targets and solves this problem elegantly.

AOP divides code into base-code (code for your functionality) and a new construct called aspect. Aspect encapsulates these cross-cutting concerns using the following concepts

  • join-points: The points in the structure of base-code where the cross-cutting functionality needs to execute. This is typically when specific methods are entered or exited or properties are accessed.
  • point-cut: A logical description of join-points using some specific syntax
  • advice: additional code like logging and security check that each of these methods need to perform

The most mature AOP language is probably AspectJ which adds AOP extensions to Java. However, for this blog, I'd stick to .NET languages like AspectDNG, Aspect# and C#.

Comments

  1. 12 Feb 2009 at 16:35
    Great article and perfect example. It was exactly what I was looking for!
  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Aspect Oriented Programming using .NET.

Leave a comment

Sign in or Join us (it's free).

Abhinaba Basu

Related podcasts

  • Introduction to AOP

    Podcast (MP3): Download Hosts: Markus Guests: Christa Schwanninger, Iris Groher Recording venue: This episode is a systematic introduction to Aspect Oriented Programming (in contrast to the interview with Gregor Kiczales). We discuss the fundamentals of AOP, defin...

Events coming up

  • Dec 9

    GL.net Group Meeting - December 2009

    Gloucester, United Kingdom

    The beginning of this year holiday season will belong to mocks. Ronnie and Stephen will take us for a tour around exciting world of unit testing.

Want to stay in touch with what's going on? Follow us on twitter!