I would like to ask for 3 information here:
There is no integrated solution for Aspect Oriented Programing (AOP) in C# (.Net) from Microsoft is that correct ? Is there any such solution under development or planned ?
What solutions are there that allow Aspect Oriented Programing (AOP) to be used in C# (.Net) ? What are they advantages/disadvantages ? I haven't find any comprihensive list that would contain all avatable options and some information for me to decide which is the one to use. The closest is this list.
What is (in your opinion) the best AOP solution for C#(.Net) considering following criteria:
I think that if something fullfils most of criteria in 3. then it is a candidate for a generaly used solution. And I cannot find anywhere if some of existing solutions fits to my needs.
As Adam Rackis points out, Post# is the way to go, it is as close you will get to AspectJ on the .NET platform.
Main differences is obviously that AspecJ has language support for aspects while Post# is a post compile weaver for .NET assemblies. (thus no language integration)
However, Post# can use join points such as field access, try catch blocks, both calls and functions (that is, caller and callee)
No not even close, AspectJ is a language, Post# can use custom pointcuts but the most common is to use attributes to decorate methods to be pointcutted(eh..grammar?)
check
everything but language support
check
check - it is a post compile weaver
limited, the weaver will generate intellisense information and show what methods have been affected
If you want a .NET language that supports aspects, check out http://aspectsharpcomp.sourceforge.net/samples.htm
Regarding different approaches, there are a few:
Post compile weaving , this is what Post# does. It simply mangles the .NET assembly and injects the aspect code.
Real Proxy / MarshallByRefObject. Based on remoting infrastructure. Requires your classes to inherit from a base class. Extremely bad performance and no "self interception"
Dynamic Proxy. This is what my old library NAspect used. you use a factory to create a subclass of the type on which you want to apply aspects. The subclass will add mixin code using interfaces and override virtual methods and inject interceptor code.
Source code weaving. As the name implies, it transforms your source code before compilation.
[edit] I forgot to add this one to the list:
Client -> Interface Proxy -> AOP interception -> Target/Subject
This is AFAIK what Spring does.
1) and 3) are the most common. They both have pros and cons:
Post Compilation:
Pros:
Cons:
Can not apply aspects based on context, that is , if a type is affected, it will be affected for the entire application.
Pointcutting private, static, sealed constructs may lead to confusion since it breaks fundamental OO rules.
Dynamic Proxy:
Pros:
Contextual, one typ can have different aspects applied based on context.
Easy to use, no configuration or build steps.
Cons:
Limited pointcuts, only interface members and virtual members can be intercepted
must use factory to create objects