Post processing stage of interception behaviour

Jun 5, 2010 at 8:26 AM

Hi, I'm struggling to figure out how to get my custom interception behaviour to be invoked when the method call is finished - the post processing stage. In fact, I'm unsure how you specify within the behaviour the pre and post processing stages as mentioned below. It's important to note that my interception behaviour is being invoked pre processing.

"These calls pass through the interception behaviors, executing the preprocessing stage of each one, with the final behavior in the chain passing the call to the target object. The return value from the target object passes back through the behaviors in the reverse order, executing the post-processing stage of each one. The first behavior in the pipeline then passes the result back to the caller."

I am missing something obvious?

Jun 5, 2010 at 6:02 PM

The stages are more conceptual that physical. Every behavior will have it's invoke method called before the final call. When it calls getNext(input, getNext)(), that's when the rest of the interception behaviors and the target method runs. After getNext returns, then you can do post processing.

So, for a behavior that only does post-processing, do something like this:


public IMethodReturn Invoke(IMethodInvocation input, GetNextINterceptionBehaviorDelegate getNext) {
    IMethodReturn result = getNext(input, getNext)();

    ... do post processing here ...
    return result; // or whatever result value you want

If you want to just pass through the return value from the target method, just return the same thing getNext returned. If you want to change the return value (to eat an exception, for example), there's a couple methods on the input object:

CreateMethodReturn for returning a value

CreateExceptionMethodReturn for returning an exception.


Jun 5, 2010 at 8:52 PM

Thanks for clarifying that - I was right, I was missing something obvious :)

I guess I was envisioning that the Invoke method was called again during post-processing - and getNext was used just to determine what was called next (another behaviour or the target).