Implement Option 1 like this
public void InterceptAsynchronous<TResult>(IInvocation invocation)
{
invocation.ReturnValue = InternalInterceptAsynchronous<TResult>(invocation);
}
private async Task<TResult> InternalInterceptAsynchronous<TResult>(IInvocation invocation)
{
// Step 1. Do something prior to invocation.
invocation.Proceed();
var task = (Task<TResult>)invocation.ReturnValue;
TResult result = await task;
// Step 2. Do something after invocation.
return result;
}
If in Step 1 and Step, if we use await with asynchronous operations, then when invocation.Proceed() it will re enter the InterceptAsynchronous