1 / 16

Aspect-oriented programming

Aspect-oriented programming. robert maclean www.sadev.co.za ∞ @ rmaclean ∞ robert@sadev.co.za. Agenda. What, when, why of AOP? How is it implemented in PostSharp and how does it work? Alternatives to PostSharp Looking to the future Discussion. Every project has “boring” code.

zinna
Download Presentation

Aspect-oriented programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Aspect-oriented programming robertmaclean www.sadev.co.za ∞ @rmaclean ∞ robert@sadev.co.za

  2. Agenda • What, when, why of AOP? • How is it implemented in PostSharp and how does it work? • Alternatives to PostSharp • Looking to the future • Discussion

  3. Every project has “boring” code source: Microsoft Application Architecture Guide, 2nd Edition

  4. AOP Details • Goal to make cross cutting concerns easy to implement and focus on business code • Xerox PARC in 2001 • AspectJ • Many implementations now days • AKA: AOSD

  5. Scenario code – simple prime calculator Customer says it’s wrong. We need logging to diagnose…

  6. Let’s add logging – trace input & output Easy to miss some places Lots of repetition of code Need to teach this Not portable 5 extra lines of code

  7. What about some procedural help? Not junior friendly Need 1 per signature 15 extra lines of code

  8. So how does aspects solve that? Feel like you are missing something? 1 extra line of code

  9. Demo time…

  10. Under the hood IL modified Source: .NET Reflector 6.8

  11. Many ways to implement AOP in .NET currently • Popular: • IL Weaving @ compile or JIT • PostSharp & Mono.Cecil • Less: • Hooking into .NET profiler API • Proxies

  12. Hooking the profiler • Disadvantages • Poor performance • Exceptionally complex • Not designed for this • Advantages • Nothing is safe from it’s power • Solves some fringe cases (i.e. mocking static methods) Application COM API Profiler CLR Environmental

  13. Proxies Proxied Normal Method Call Method Call Proxy Object • Disadvantages • Complex with ContextBoundObject • Perf is worse than IL weaving • Advantages • Using DI it can be easier • Perf is better than .NET profiler Object

  14. Future: Post Roslyn Theory • Roslyn • Next version of C#/VB “compiler” • Written in managed code • Available as a service • Post Roslyn • Insert new language semantics • Approach the AspectJ style

  15. Summary • AOP • Way to untangle cross cutting concerns out of business code • Great re-use • Can be easy to use (depending on implementation) • Many options to do this!

  16. Questions & Discussions

More Related