Over a million developers have joined DZone.

Aspect-Oriented Programming in .NET

Today I attended Austin Code Camp 2010 and as I had stated, I also had one hour session on Aspect-Oriented Programming (AOP) in .NET where I talked about this programming paradigm that is a very powerful way to enhance the development experience and I believe that it will be something common in the next few years.

I started my talk with developing the motivation and the problem that drives us to have Aspect-Oriented Programming as a solution. After that I introduced AOP as the solution to this problem and talked about its position among programming paradigms.

In the next section of my session I went over some principles of AOP including the concept of cross-cutting concerns, aspect, join-point, point-cut, and advice. The session followed by a discussion on common misconceptions about AOP, potential issues with it, and a list of some big projects written in Java that use this approach.

One major section of the session was dedicated to the language support for Aspect-Oriented Programming and what we need to accomplish it in a language as well as the concept of weaving and how a weaver works by exemplifying that in the case of the .NET Framework, and introducing common techniques to implement AOP in .NET and a list of frameworks for AOP.

The next part of the talk was a brief introduction to PostSharp as one of the best AOP tools for the .NET Framework followed by two examples for logging and caching in a sample ASP.NET MVC application along with a discussion on the generated IL code by PostSharp.

I have to note that I had a mistake here that I had the impression that PostSharp relies on a Windows Service after installation but it doesn’t. Actually, it uses a post-build MSBuild task to detect the builds and integrate aspects into the code in order to generate a new IL code. Well, for unknown reasons I had the impression that it has a Windows Service!

The last part of the talk focused on AOP and Dependency Injection and how to achieve AOP via Dependency Injection with an example in Castle Windsor as well as a brief discussion about applying AOP to simplify Dependency Injection and inject the services in a join-point.

The closing remarks of my session were a look at the future of AOP in .NET, some resources for further reading, the availability of three free commercial licenses for PostSharp, and finally some acknowledgments for some people who helped me for this session (especially Dr. Shonle who has had advanced academic research and publication on AOP).

I think it’s worth mentioning here again that unfortunately Aspect-Oriented Programming is not well-promoted by the .NET community (unlike the Java community) and we need to do more work in this area. I hope I can have more specialized blog posts on AOP in .NET in the future.

I have to thank the organizers of Austin Code Camp 2010 for this great event and everyone for coming. I also would thank SharpCrafters for sharing free licenses with the attendees. I only could make it to Matt Hinze’s session on hard lessons learned from being stupid about Test-Driven Development and half a session by Rob Vettor on Visual Studio 2010 debugging. I had to head back to San Antonio earlier as I was so tired and couldn’t stay awake anymore!

I’ve published my slides here. It’s planned to publish the videos of sessions on Viddler. In that case I will update this post with the link to the video as well.


Published at DZone with permission of Keyvan Nayyeri. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}