Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement IAsyncInterceptor interface to intercept invocations, invocation.Proceed() re enter InterceptAsynchronous if we perform async operations with awai #232

Open
ng-le opened this issue Oct 6, 2024 · 0 comments

Comments

@ng-le
Copy link

ng-le commented Oct 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant