<= Home

“Aspects“of Encase During Runtime

Posted about about 1 year ago

This is the high-level view of the Encase framework and how it applies aspects and AOP concepts.

 

To clarify terminology, I use the term wrapped object to indicate an instance of class that you have passed into the Encase framework that can contain aspects and mixins. The encase framework achieves aspect orientation by creating new classes using the System.Reflection.Emit namespace to dynamically create new types (this is commonly referred to as emitting). Encase does the following using the ProxyCreation namespace classes in the framework:

1.      Inherits the new type from the type of object you wish to aspect (we can refer to this as the Aspected Object).

2.      Creates overrides on every virtual method in the Aspected Object class. In the overridden methods if forwards the call to the AspectedInterceptor (or an instance of IProxyInterceptor if you supply your own interceptor) that will apply pointcuts, execute advices, and then call the method back on the Aspected Object.

3.      Creates implementations of every interface implemented by mixins. In these new implemented methods the code forwards invocation to the AspectedInterceptor for handling of pointcuts, advices, and then invokes the method back on the mixin instance.

4.      Creates an instance of the new type just emitted.

5.      Takes the original object and copies all (private/protected/public) fields into the same appropriate fields of the instance of the newly created type.

 

To best visual what is happening when an object is wrapped, it helps tremendously to understand the decorator pattern. In really Encase is just making implementations of the decorator pattern on the fly to the objects you wish to apply aspects.

 

Additional Documentation:

IPointcut

Encaser

IAdvice