Intro to Aspect Oriented Programming with PostSharp–Part 1

This is a a quick blog post to announce that I will be doing a series that introduces developers to Aspect Oriented Programming using a great tool called PostSharp.

In order to make the journey easier for beginners I packaged up some very basic aspects into a nuget package that can be downloaded from the nuget package manager.  Search for PostSharp-Aspects.

Note: Any errors or improvements or if there is an aspect you would like to see added, please let me know.  My contact information is listed in the about area.

What is PostSharp?

A quick definition is that PostSharp is an Aspect-oriented programming (AOP) framework for the .NET platform. It conducts a method known as “static weaving” or “IL weaving”, which means it applies the “Aspects” at compile time after the dll/exe’s have been compiled.

Aspects are code written in C# classes which get turned into behaviors based on the attributes of the code.

AOP according to Wikipedia: In computing, aspect-oriented programming (AOP) is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns.

Some of the value behind AOP and utilizing PostSharp are:

  • Source is easier to understand
  • Source is easier to refactor/manage
  • Source is easier to introduce to new developers
  • 15% less code
  • 20% less coupling

Below is a chart that I found from an article by Dustin Davis that shows some of the advantages of AOP.

CropperCapture2_thumb2

I will go into greater detail about the Aspects included in the next few post.  For now if you would like to play you can do the following after installing the package to your project.

  • If you would like to add the aspects to everything in project (I have tested and verified they work with C# console,MVC 3/4, and Silverlight 5 applications)
    • Add the following to your AssemblyInfo.cs file
      [assembly: ExceptionHandler]
      [assembly: ProfileTrace]
    • Or they can be added individually by code annotation to either a method or class.
      [ExceptionHandler]
      [ProfileTrace]
      private void UpdateCustomer()
      {
      	somecode...
      }
Advertisements
This entry was posted in PostSharp and tagged , , . Bookmark the permalink.

2 Responses to Intro to Aspect Oriented Programming with PostSharp–Part 1

  1. Pingback: How PostSharp has improved my ability to follow SRP | Research ~ A ~ holic

  2. Pingback: PostSharp .. User Group .. Code Camp != Sleep | Research ~ A ~ holic

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s