Codedom and Static Proxy - Codedom is my lover
There are two kinds of AOP: Dynamic and Static. Now Future.AOP get AOP information by reading xml file. Everytime, when executing methods, Future.AOP need to search the mapping objects of all xml files to make sure whether these methods should be intercepted. This is a typical Dynamic AOP.
The benefit of Dynamic AOP is to have the ability of dynamic update. But it is very inefficient. I think that I should give the ability of dynamic update to Future.AOP.
My new idea is to generate a binary proxy(dll or exe) file by scanning any assemblies(dll or exe) and some aspect xml files that is correlative with these assemblies. Then these assemblies load the new binary proxy file, not the aspect xml file. The before, after, around actions will be woven into the binary proxy file.
The following code is a sample.
public class Class1
{
public virtual void Method1()
{
……
}
}
public class StaticProxy : Class1
{
public override void Method1()
{
Interceptor.before(…) ; // if before action is not allowed, then the line code will be inexistent.
Class1.Method1(); // or Interceptor.around
Interceptor.after(…) ; // if after action is not allowed, then the line code will be inexistent.
}
}
The above code may be generated by many approaches. e.g. generating by filestream, Reflection Emit API, codedom and so on. But I fancy Codedom most. She looks like my lover. I can write source code straight by Codedom. It can generate the source file(*.cs, *.vb…) and binary(*.exe, *.dll)。I don’t think about languages, because it is independent of language syntax.