Skip to content

AsyncInterceptor for Castle.DynamicProxy.

License

Notifications You must be signed in to change notification settings

heku/Kunet.AsyncInterceptor

Repository files navigation

Kunet.AsyncInterceptor

Build on Push Nuget Version

Inspired by stakx.DynamicProxy.AsyncInterceptor, but rewrite with less reflection to get better performance.

This library allows you to smoothly connect Castle.DynamicProxy with your async/await code, it provides an abstract AsyncInterceptor class, your interceptor inherited from this class can get the ability to intercept method which return value is Task, Task<T>, ValueTask or ValueTask<T>. You are also able to extend the library to support custom task-like types.

class Example : AsyncInterceptor
{
    // This gets called when a non-awaitable method is intercepted:
    protected override void Intercept(IInvocation invocation)
    {
        invocation.Proceed();
        invocation.ReturnValue = ... ;
    }

    // Or this gets called when an awaitable method is intercepted:
    protected override async ValueTask InterceptAsync(IAsyncInvocation invocation)
    {
        await invocation.ProceedAsync();
        invocation.AsyncResult = ... ;
    }
}