Why all handlers are not being called on method in call chain?

Nov 2, 2011 at 4:15 PM

I have created method handlers in Unit to intercept calls and configured everything correctly, however, when I make call to the method, it invokes hanlder for the entry method only and not for all subsequent methods being called by this method.


e.g. my class has MethodA, MethodB,MethodC. All I have decorated with call handler attributes. The code is written such that MethodA calls MethodB, and MethodB calls MethodC. Now I instantiate type through unity container.Resolve method. I have configured the type mappers and proxy interceptor for TransparentProxyInterceptor. When I make a call to MethodA, it calls the handler, however, I don't get handler calls for MethodB and MethodC.


Can you tell me how to enable this? Or is it required to call MethodB and MethodC from the proxy instance then and only then it will work?


Please Advise...

Nov 2, 2011 at 5:58 PM

Calls that go through the interception logic get interceptors run. In the case of one of the instance interceptors (transparent proxy or interface interceptors), the interception logic is in the proxy, not in the target object. So you are correct, the calls won't get intercepted unless they go back through the proxy if you're using TransparentProxyInterceptor.

Another option would be to mark MethodA, MethodB, and MethodC as virtual, and use the VirtualMethodInterceptor instead. That puts the interception logic into the target object (in the dynamically generated subclass) so that lets self calls get intercepted as well. This obviously only works on instances that are created by the container / via the interception API.