Aspect Oriented Programing is a method of programming where every method is wrapped with some functional unit of work. For instance, by creating a single “aspect”, developers can wrap every method of a class in a try/catch block, trace calls, or any other desired global effect. This talk will center around creating a class to serve as an aspect tempalte, reflecting on that class and generating a proxy to another class. We will use the infrastructure from DynamicProxy to pick and choose which methods to proxy, but will use reflection and straight IL emission to generate more performant proxies.
We will be using the practices from this post to do our reflection.
Castle.DynamicProxy is a widely used and well respected proxy generator. Although, it is mainly used to create proxies on the fly (using caching for optimization), it can create proxy assemblies to increase start up performance. It is highly extensible, but most application developers only use it to inject interceptors into their proxies. We will be using it to generate our proxies from our modified MSIL.
You can find out more about DynamicProxy from Krzysztof Kozmic's excellent tutorial:
In this session, we will write a functional class and an aspect class. Then, using our aforementioned tools, we will generate a class which weaves the aspects into a proxy. This proxy generation can happen at run time or at compile time and unlike the use of just Castle.DynamicProxy alone or similar proxy generators, the solution presented here will allow applications to do quite complex things with no invocation-time reflection.
For best understanding of this session, a strong grasp of reflection and some understanding IL is required. I will try to update this session description as I find more online documentation to share.