Aspect oriented programming

1,655 views

Published on

AOP is a way of making code easier to write and work with by extracting cross cutting concerns into small easily reusable code that is applied with attribututes. This session looks at that and the various options available to us, from free items to commercial offerings like PostSharp.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,655
On SlideShare
0
From Embeds
0
Number of Embeds
272
Actions
Shares
0
Downloads
29
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Aspect oriented programming

  1. 1. Aspect-oriented programming<br />robertmaclean<br />www.sadev.co.za ∞ @rmaclean ∞ robert@sadev.co.za<br />
  2. 2. Agenda<br />What, when, why of AOP?<br />How is it implemented in PostSharp and how does it work?<br />Alternatives to PostSharp<br />Looking to the future<br />Discussion<br />
  3. 3. Every project has “boring” code<br />source: Microsoft Application Architecture Guide, 2nd Edition<br />
  4. 4. AOP Details<br />Goal to make cross cutting concerns easy to implement and focus on business code<br />Xerox PARC in 2001<br />AspectJ<br />Many implementations now days<br />AKA: AOSD <br />
  5. 5. Scenario code – simple prime calculator<br />Customer says it’s wrong. We need logging to diagnose…<br />
  6. 6. Let’s add logging – trace input & output<br />Easy to miss some places<br />Lots of repetition of code<br />Need to teach this<br />Not portable<br />5 extra lines of code<br />
  7. 7. What about some procedural help?<br />Not junior friendly<br />Need 1 per signature<br />15 extra lines of code<br />
  8. 8. So how does aspects solve that?<br />Feel like you are missing something?<br />1 extra line of code<br />
  9. 9. Demo time…<br />
  10. 10. Under the hood<br />Source: .NET Reflector 6.8<br />IL modified<br />
  11. 11. Many ways to implement AOP in .NET currently<br />Popular: <br />IL Weaving @ compile or JIT<br />PostSharp & Mono.Cecil<br />Less:<br />Hooking into .NET profiler API<br />Proxies<br />
  12. 12. IL Weaving<br />.cs or .vb code<br />IL (pure)<br />PostSharp<br />IL (Merged)<br />
  13. 13. Hooking the profiler<br />Disadvantages<br /><ul><li>Poor performance
  14. 14. Exceptionally complex
  15. 15. Not designed for this</li></ul>Advantages<br /><ul><li>Nothing is safe from it’s power
  16. 16. Solves some fringe cases (i.e. mocking static methods)</li></ul>Application<br />COM API<br />CLR<br />Profiler<br />Environmental<br />
  17. 17. Proxies<br />Proxied<br />Normal<br />Method Call<br />Method Call<br />Proxy<br />Object<br />Disadvantages<br /><ul><li>Complex with ContextBoundObject
  18. 18. Perf is worse than IL weaving</li></ul>Advantages<br /><ul><li>Using DI it can be easier
  19. 19. Perf is better than .NET profiler</li></ul>Object<br />
  20. 20. Future: Post Roslyn Theory<br />Roslyn<br />Next version of C#/VB “compiler”<br />Written in managed code<br />Available as a service<br />Post Roslyn<br />Insert new language semantics <br />Approach the AspectJ style<br />
  21. 21. Summary<br />AOP<br />Way to untangle cross cutting concerns out of business code<br />Great re-use<br />Can be easy to use (depending on implementation)<br />Many options to do this!<br />
  22. 22. Questions & Discussions<br />

×