49

Are there any good resources to wrap my head around Aspect Oriented Programming?

PS: I need to understand AO programming, not the libraries or frameworks available for .NET or C# :)

tshepang
  • 12,111
  • 21
  • 91
  • 136
TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188

4 Answers4

56

Just to get your head around it: It is the ability to hook events such as: creation of objects, setting of properties, etc, and attach general functions to them, that will be populated with relevant context.

Because C# doesn't have an inbuilt facility for this, you need a framework, like PostSharp, to do 'bytecode weaving' (i.e. just writing code to actually make the calls, directly to your classes) to simulate it.

Noon Silk
  • 54,084
  • 6
  • 88
  • 105
  • 4
    On a side note, http://www.postsharp.org/ has a great explanation of what it is and it's uses. – RCIX Sep 13 '09 at 05:22
  • Yes postsharp is good thing (also have good site!) – TheVillageIdiot Sep 13 '09 at 17:35
  • 1
    runtime emit is also good. Unity and others use reflection emit to do method interception. Also .net does have a hook ContextBoundObjects like Jean mentioned. Unfortunetly there is a huge perf hit with context bound objects. – AbdElRaheim Oct 26 '12 at 06:32
4

check this out, it is describing how to implement AOP ( log, timing, tracing, exception handling...) using postsharp

http://www.codeproject.com/Articles/337564/Aspect-Oriented-Programming-Using-Csharp-and-PostS

Muhammad Soliman
  • 21,644
  • 6
  • 109
  • 75
3

Aspect Oriented Programming means having a meta level where yo can define logging or security/access control features to interweave with your code instead of implementing these feature very time in your code. So instead of beeing one-dimensional, you have to program two-dimensional.

I know this may sound very esotheric but it is easy once you understood it.

AOP often works with proxy classes which intercept calls and do things in the background.

codymanix
  • 28,510
  • 21
  • 92
  • 151
3

A good link below, shows you how to code up an AOP framework of your own. Unfortunately, all of your consuming classes have to inherit from the MarshalByRefObject (through ContextBoundObject).

http://www.developerfusion.com/article/5307/aspect-oriented-programming-using-net/3/

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72