Introduction to PostSharp and AOP slides and code

by Call me dave... 25. January 2009 21:30

On Thursday I participated in the Open Source .NET Exchange held by Skills Matter

It was a great night.  The venue was full and I and the other speakers received lots of positive feedback (although my microphone was not on correctly so I ended up shouting…).  As you can imagine, during a 15 minute speech, you can only scratch the surface of a topic.  However, with the talks being so diverse, I think most people, including myself, learnt a lot.

I especially liked Mike’s talk on the repository pattern.  Comparing and contrasting different implementations of a complex pattern/technique is a powerful method to understand the inevitable hidden intricacies.  His advice about being weary of using a single generic repository interface or base class for all repository’s was very timely.  In some code, I recently reviewed, the developer using NHibernate to populate a read only report.  Unfortunately within the project wide repository there were save and delete methods available.  Clearly this throws out the underlying read only nature of the data out the window.  Following Mike’s advice our team will be moving away from trying to be overly clever, with the design, of our repositories and move instead to ones that clearly identify the base aggregates and clearly expose the expected behavior of the root object at run time.

Interestingly I spent more time discussing the features of Active MQ with David and a group of people interested in using NMS than PostSharp.  David and I worked on a project where we used the Publish-Subscribe capabilities of Active MQ to push data to clients that were running Flash/ActionScript.  Using Push technology, as opposed to Pulling from database, reduces load and increases scalability.  We are using the same technique at a large finance company to push market prices directly to client machines running WPF.  In the .NET community people it is common for MSMQ to be used as the messaging infrastructure.  This choice heavily limits the design. 


  • does not provide Publish-Subscribe capability – Although it can be emulated with NServiceBus/Mass Transit
  • does not allow you to tag messages with metadata which can then be used for intelligent filtering/routing
  • has a 4 MB limit on message size

On the PostSharp front there was a lot of interest in using PostSharp to “break the build” since its such a quick win for teams that are using NHibernate. I will try to blog about this technique in a little bit more detail soon.


Slides and Source

As promised here are the slides and the source code that were used during the presentation. 

To use the code download and install PostSharp using the default settings.  This will configure MS Build to automatically invoke PostSharp whenever the PostSharp.Laos.dll assembly is referenced.