Editorials

Try Aspect Programming in the New Year

A few months ago I presented the concept of Aspect programming. Aspect programming is a technique of applying a common functionality across all aspects of your application without directly writing the code to make it happen. Instead, you link your aspects to your code with a language that looks for patterns in your code, and assigns the activity to some feature in your aspect code.

Some aspect coding is done at runtime through the use of a dynamic proxy. Others are done as a pre-processing step during code compilation.

PostSharp is a library that has been designed to take advantage of aspect programming in C#. It applies transformations based on your aspect definitions as part of the compilation of your code.

From the PostSharp web, http://www.postsharp.net/aspects, site you find the following steps as to how to integrate Aspects into your business code.

  1. Think about how you would explain the pattern to your colleague.
  2. Grab a pencil and, in plain English, write what needs to be transformed (e.g., all public methods) and how (e.g., add a try/catch block and call the exception handling service).
  3. Translate your ideas into code: create an aspect class and add building blocks for each code transformation.
  4. Apply the aspect to your business code.
  5. Build your project.

Take a look at the PostSharp web site for ideas how Aspect programming can save you time and increase the capabilities of your applications with reduced work.

Do you have other aspect tools you’d like to recommend? Share them here, or in email to btaylor@sswug.org.

Cheers,

Ben