Bernie Cook's Blog

Azure, C#, .NET, Architecture & Related Tech News

Leave a comment

Using dotPeek to Review IL Weaving

dotPeekThere are two types of Aspect Oriented Programming (AOP) in .NET; Interceptors and IL weaving. This post focuses on the later and illustrates how you can use a .NET decompiler to review the code generated by AOP post compilation processing using the IL Weaving approach, albeit the decompiled code.

The most well known AOP framework for .NET is PostSharp, which is what I’ll be using in this post. And one of the more well known .NET decompilers is dotPeek, developed by JetBrains, the company best known in the .NET world for ReSharper. You do have to pay for PostSharp (although there is a trial period), however dotPeek is free and simple to download and execute.

So what I’ve done is provide (1) the source code for a simple .NET console application I’ve knocked together, displaying the resulting decompiled code in dotPeek, then (2) I decorate one of the application’s methods with an AOP aspect and display the resulting decompiled code so you can see what PostSharp has done. Continue reading



Repository Caching with Aspect Oriented Programming

Repository Caching with Aspect Oriented ProgrammingThis post provides a walkthrough of how to implement basic cache handling at the repository layer using Aspect Oriented Programming (AOP). I’ve chosen PostSharp’s AOP framework and built a relatively simple Domain-Driven Design (DDD) solution in .NET to illustrate how it all ties together.

I want delve into too much AOP detail up front other than to reiterate the usual AOP pitch – that it’s an incredibly useful programming paradigm which addresses cross-cutting coding concerns within application development. What does that mean in English? Once you’ve mastered the basic AOP terminology and implementation requirements you can use it to remove a lot of duplicate code that appears throughout your solution. If you’re not familiar with AOP then take a quick moment to watch one of PostSharp’s many introductory screencasts or browse through their documentation. Keep in mind that AOP isn’t OOP as you work your way through the following code, it complements OOP extremely well but doesn’t follow object-oriented principles. Continue reading