Spring.Net, Feb 2008, PostSharp: A Technical Introduction
-
Upload
gfraiteur -
Category
Technology
-
view
1.456 -
download
1
description
Transcript of Spring.Net, Feb 2008, PostSharp: A Technical Introduction
PostSharp & PostSharp & Spring.NETSpring.NET
2. PostSharp Architecture
you are now supposed to be woken up!you are now supposed to be woken up!
however, you should already know that!however, you should already know that!
The Big PictureThe Big Picture
Plug-InsPlug-Ins
PostSharp CorePostSharp Core
PostSharp LaosPostSharp Laos
HostsHosts
MSBuild HostMSBuild Host Command-Line Host
Command-Line Host
Runtime Host
A finer pictureA finer picture
PostSharp CorePostSharp Core
Code Object Modelrepresents a .NET module
Code Object Modelrepresents a .NET module
Module Readerreads a .NET binary assembly into the Code Object Model
Module Readerreads a .NET binary assembly into the Code Object Model
Module Writerwrites the Code Object Model
into a binary assembly (using ILASM)
Module Writerwrites the Code Object Model
into a binary assembly (using ILASM)
Code Weaverprovides the infrastructure
for MSIL injection
Code Weaverprovides the infrastructure
for MSIL injection
Platform Infrastructure
executes projects, loads plug-ins,loads and schedules tasks
Platform Infrastructure
executes projects, loads plug-ins,loads and schedules tasks
Plug-inperforms specific analysis
or transformation
Plug-inperforms specific analysis
or transformation
Hostbootstraps PostSharp andinvoke project executions
Hostbootstraps PostSharp andinvoke project executions
Independent Programuses PostSharp without
the Platform Infrastructure
Independent Programuses PostSharp without
the Platform Infrastructure
PostSharp LaosPostSharp4EntLib
PostSharp.Samples.Tracecustom plug-ins
PostSharp LaosPostSharp4EntLib
PostSharp.Samples.Tracecustom plug-ins
command-line utilityMSBuild task
PostSharp.Samples.Hostcustom application servers
command-line utilityMSBuild task
PostSharp.Samples.Hostcustom application servers
PostSharp.Samples.ExplorerPostSharp.Samples.Explorer
Core vs. LaosCore 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
Hello,World
Compared Example: LoggingBoring but instructive
have you done your homework?have you done your homework?
The Laos SolutionThe Laos Solution
Derive a custom attribute.Implement “event handlers”.Apply/multicast the custom attribute.Compile-time instantiation.Deserialization.Reflector.
The Core SolutionThe Core Solution
Define the Public Interface.◦Custom Attribute in the example, but anything
else is allowed (XML, DSL).Implement the weaver.
◦Advice.◦Advice Provider (pointcut evaluation).
Plug-In Manifest.Discovery.Reflector.
Compound AspectsImplement INotifyPropertyChanged.
Translating the implementation Translating the implementation pattern to AOPpattern to AOP
Aspected Class
Property 1Property 1
Property 2Property 2
Property 3Property 3
NotifyPropertyChangedImpl
internal OnPropertyChangedinternal OnPropertyChanged
event PropertyChangedevent PropertyChanged
Property Setter Aspect
OnSuccess handlerOnSuccess handler
Composition Aspect
Putting it together: Putting it together: Compound AspectCompound 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.
SummarySummary
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.◦No division of compile-time and run-time logic.◦Attention to abuses!