tags:

views:

237

answers:

6

Hi All,

I am very interested in Aspect Orientated Programming (Spring, PostSharp etc). I can think of a couple of ways I would employ this, mainly logging or lazy load comes to mind. I was hoping to see what everyone else used it for?

Please list out the senarios you solve using AOP. (hopfully it may inspire some one else to pick it up too)

cheers

bones

+1  A: 

Attributes in C# can be examples of AOP -- for example, the AuthorizeAttribute in ASP.NET MVC applies authorization requirements across methods or classes decorated with the attribute.

tvanfosson
+1  A: 

I used AOP for one major project in 2007/2008. The company I was working for had me developing a custom CMS to manage their clients. It was integrated into the custom framework we developed and could conditionally render content based on the user's metadata through our rules engine.

Our environments were split up into the traditional Dev/QA/Staging/Production. We needed a way to migrate entities, be it content or other data, between the environments. I used AOP to track changes to property values, essentially recording and versioning all changes to entities made in the downlevel environments. Using reflection, entities were copied by "replaying" in a target environment the changes made in a source environment. I called the system ChangeFlow because it was integrated into a workflow system. Content approvers could approve a current version, which would inititate the migration. Any object could be "ChangeFlow enabled" by deriving from a common base class and adding a few attributes to the methods and properties that needed tracking.

Dave Swersky
+1  A: 
  • Security - declare required permissions/roles and apply some advice that has knowledge of the current Principal to make authorization decisions
  • Object pruning - snip off various parts of an object graph using advice
  • Transactions - apply transactional behavior to methods that have no knowledge of transactionality
  • Timing code

Logging is often cited as an example but in practice I find it isn't very useful. Logging statements inside of methods tend to be more valuable.

As suggested above, adding attributes to classes or methods and then using AOP to introspect that metadata and perform logic is a great way to decouple that logic from the code. You can also make the declarations in a separate artifact (XML) but I find the attribute approach very powerful.

cliff.meyers
+2  A: 

I agree with the post by brd6644 (and would have voted it up if I could). Especially his comment on logging. Using aspects for logging is more akin to tracing.

There are two podcasts on se-radio.net on AOP. The first, and interview with Gregor Kiczales, who has done a lot of research on AOP; the second, more recent interview with Christa Schwanninger and Iris Groher focuses on how AOP is used in practice. Both are worth a listen.

Finally, be careful in how you adopt AOP. Too much focus on AOP and you are concentrating on the platform rather than delivering business value. I have never been directed to use AOP by a test case. Aspects are something I would introduce during refactoring of an app to remove duplication.

ewalshe
+1  A: 

You might want to have a look at this question...

Dan Vinton
A: 

This is all exellent.

Any one else using this for anything?

dbones