At SharpCrafters, we started to work on PostSharp even before SharpCrafters existed: in 2004. PostSharp 2.0 is the third major release of PostSharp (after 1.0 and 1.5) and makes PostSharp the most popular and by far the most advanced framework for aspect-oriented programming in .NET.
What's New In PostSharp 2.0?
PostSharp 1.0 and 1.5 made aspect-oriented programming (AOP) popular in the .NET community. PostSharp 2.0 makes it mainstream by enhancing convenience (Visual Studio Extension), reliability (dependency enforcement), run-time performance (optimizer), and features (composite aspects, property- and event-level aspects).
Visual Studio Extension
As developers start being comfortable with PostSharp and add more and more aspects to their code, two questions become manifest: How can I know to which elements of code my aspect has been applied? How can I know which aspects have been applied to the element of code I am looking at? Answering these two questions is precisely what the PostSharp Extension for Visual Studio 2008 and 2010 has been designed for. It provides two new features to the IDE: an Aspect Browser tool window, and new adornments of enhanced elements of code with clickable tooltip.
Composite Aspects (Advices and Pointcuts)
Part of the success of PostSharp 1.5 was due to its ability to introduce aspects without appealing to barbaric terms such as advices and pointcuts. So why to introduce them now? Because they make it easier to develop complex aspects. Thanks to advices and pointcuts, you can implement complex patterns such as observability awareness (INotifyPropertyChanged) with just a few lines of code. And just with PostSharp 1.5, you can still write your own aspects without knowing about advices and pointcuts.
Adaptive Code Generation
PostSharp 2.0 generates much smarter, faster, and smaller code than before. Let's face it: PostSharp 1.5 was quite dumb. It generated a lot of instructions that your aspects did not even need. PostSharp 2.0 analyzes your aspect to see which features are actually being used at runtime, and generates only instructions that support these features. Result: you could probably not write much faster code by hand.
Interception Aspect for Fields and Properties
PostSharp 2.0 comes with a new kind of aspect that handles fields and properties: LocationInterceptionAspect (in replacement of OnFieldAccessAspect). The aspect is much more usable than its predecessor; for instance, it is possible to call the field or property getter from the setter.
Interception Aspect for Events
The new aspect kind EventInterceptionAspect allows an aspect to intercept all event semantics: add, remove, and fire.
Aspect Dependencies
By enforcing aspect dependency rules, PostSharp ensures that aspects behave in a predictable and robust way, even when multiple aspects are applied to the same element of code. This feature is important for large and complex projects, where aspects may be written by different teams, or provided by numerous third-party vendors who don't know about each other.
Instance-Scoped Aspects
In PostSharp 1.5, all aspects had static scope, i.e. there was a single instance of the aspect for every element of code to which they apply. It is now possible to define aspects that have instance lifetime. For instance, if the aspect is applied to an instance field, a new instance of the aspect will be created for every instance of the type declaring the field. This is named an instance-scoped aspect.
Support for New Platforms
- Microsoft .NET Framework 4.0
- Microsoft Silverlight 3.0
- Microsoft Silverlight 4.0
- Microsoft Windows Phone 7 (Applications and Games)
- Microsoft .NET Compact Framework 3.5
- Novell Mono 2.6
Build Time Improvements
Just starting the CLR and loading system assemblies takes considerable time, too much for an application (such as PostSharp) that is typically started very frequently and whose running time is just a couple of seconds. To cope with this issue, PostSharp now preferably runs as a background application
What's New In PostSharp 1.5?
PostSharp 1.5 was published 3 years after the start of the project, and was the first release to be really production-ready.
Aspect Inheritance
It is now possible to put an aspect on an interface and have it implicitly applied to all classes implementing that interface. The same works with classes, virtual or interface methods, and parameters of virtual or interface methods. Read more...
Reading assemblies without loading them in the CLR
In version 1.0, PostSharp required assemblies to be loaded in the CLR (i.e. in the application domain) to be able to read them. This limitation belongs to the past. When PostSharp processes a Silverlight or a Compact Framework assembly, it is never loaded by the CLR.
Lazy loading of assemblies
When PostSharp has to load a dependency assembly, it now reads only the metadata objects it really needs, resulting in a huge performance improvement and much lower memory consumption.
Build-Time Performance Enhancement
The code has been carefully profiled and optimized for maximal performance.
Support for Novell Mono
PostSharp is now truly cross-platform. Binaries compiled on the Microsoft platform can be executed under Novell Mono. Both Windows and Linux are tested and supported. A NAnt task makes it easier to use PostSharp in these environments.
Support for Silverlight 2.0 and the Compact Framework 2.0
You can add aspects to your projects targeting Silverlight 2.0 or the Compact Framework 2.0. Read more...
Pluggable Aspect Serializer & Partial Trust
>Previously, all aspects were serializer using the standard .NET binary formatter. It is now possible to choose another serializer or implement your own, and enhance assemblies that be executed with partial trust. Read more...