Aspect orientated programming is ideal when you need to reduce "cross cutting" functionality within your code base. What this means is you have common code (logging, security) that classes need to implement but you cannot abstract that functionality into base classes.
So, AOP is really taking small these pieces of functionality and embedding them, at runtime or compile time, into your code where the "cross cutting" functionality is present.
Resources
Currently, AOP is not built into C# but there the following frameworks can build AOP:
AOP for thread data
Generally, using AOP to share data across threads is not the way to go. There are other techniques available for developers to do that:
[ThreadStaticAttribute]
Append this attribute to fields to dictate to the .NET runtime that the following field will be unique to multiple threads
Synchronization (most common technique) Use Mutexes
, Semaphores
, ReaderWriter
locks and EventWaitHandles
to synchronize access to local or global data from multiple threads. In C#, the lock
statement is syntactic sugar for the Monitor
class, which can be used to "lock" access to an object from a single thread.