Spring.Net, Feb 2008, PostSharp: A Technical IntroductionPresentation Transcript
PostSharp & Spring.NET 2. PostSharp Architecture
you are now supposed to be woken up!
however, you should already know that!
The Big Picture Plug-Ins PostSharp Core PostSharp Laos Hosts MSBuild Host Command-Line Host Runtime Host
A finer picture PostSharp Core Code Object Model represents a .NET module Module Reader reads a .NET binary assembly into the Code Object Model Module Writer writes the Code Object Model into a binary assembly (using ILASM) Code Weaver provides the infrastructure for MSIL injection Platform Infrastructure executes projects, loads plug-ins, loads and schedules tasks Plug-in performs specific analysis or transformation Host bootstraps PostSharp and invoke project executions Independent Program uses PostSharp without the Platform Infrastructure PostSharp Laos PostSharp4EntLib PostSharp.Samples.Trace custom plug-ins command-line utility MSBuild task PostSharp.Samples.Host custom application servers PostSharp.Samples.Explorer
Core vs. Laos PostSharp Core PostSharp Laos Objective Absolutely free editing of .NET assemblies Aspect-Oriented Programming Easily Primitives Low-Level (MSIL) High-Level Audience ISV, MSIL/PostSharp specialist Everyone Learning Curve Steep High Complexity / Error Proneness High Low Runtime performance Fast Slower Licensing of extensions GPL/Commercial Any
Compared Example: Logging
Boring but instructive
have you done your homework?
The Laos Solution
Derive a custom attribute.
Implement “event handlers”.
Apply/multicast the custom attribute.
The Core Solution
Define the Public Interface.
Custom Attribute in the example, but anything else is allowed (XML, DSL).
Implement the weaver.
Advice Provider (pointcut evaluation).
Implement INotifyPropertyChanged .
Translating the implementation pattern to AOP Aspected Class Property 1 Property 2 Property 3 NotifyPropertyChangedImpl internal OnPropertyChanged event PropertyChanged Property Setter Aspect OnSuccess handler Composition Aspect
Putting it together: Compound Aspect
True meta-programming at compile-time.
No limitation to custom attributes.
The base of PostSharp bridges to Microsoft Enterprise Library or Microsoft Entity Framework.
With PostSharp Core, you are completely free but you have to pay the price.
PostSharp Laos allows to do pretty much things, but:
It is slower: it generates suboptimal instructions .