Kunet.AsyncInterceptor 2.1.0

Prefix Reserved
dotnet add package Kunet.AsyncInterceptor --version 2.1.0
                    
NuGet\Install-Package Kunet.AsyncInterceptor -Version 2.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kunet.AsyncInterceptor" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kunet.AsyncInterceptor" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Kunet.AsyncInterceptor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kunet.AsyncInterceptor --version 2.1.0
                    
#r "nuget: Kunet.AsyncInterceptor, 2.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Kunet.AsyncInterceptor@2.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kunet.AsyncInterceptor&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Kunet.AsyncInterceptor&version=2.1.0
                    
Install as a Cake Tool

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>.

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 = ... ;
    }
}
Benchmark
.NET 8.0
Method Categories Mean Ratio Gen0 Allocated Alloc Ratio
StakxRunningTaskT RunningTask<T> 2,076.89 ns 6.64 0.1221 2104 B 2.33
KunetRunningTaskT RunningTask<T> 312.92 ns 1.00 0.0539 904 B 1.00
StakxRunningValueTaskT RunningValueTask<T> 2,908.91 ns 8.54 0.1450 2440 B 2.48
KunetRunningValueTaskT RunningValueTask<T> 340.72 ns 1.00 0.0587 984 B 1.00
StakxTask Task 916.48 ns 31.27 0.0448 752 B 4.09
KunetTask Task 29.31 ns 1.00 0.0110 184 B 1.00
StakxTaskT Task<T> 1,303.35 ns 9.44 0.0648 1144 B 2.60
KunetTaskT Task<T> 138.14 ns 1.00 0.0262 440 B 1.00
StakxValueTask ValueTask 1,713.29 ns 45.55 0.0629 1080 B 4.35
KunetValueTask ValueTask 37.62 ns 1.00 0.0148 248 B 1.00
StakxValueTaskT ValueTask<T> 2,118.77 ns 14.53 0.0877 1472 B 2.92
KunetValueTaskT ValueTask<T> 145.85 ns 1.00 0.0300 504 B 1.00
StakxVoid Void 77.71 ns 4.14 0.0062 104 B 1.00
KunetVoid Void 18.78 ns 1.00 0.0062 104 B 1.00
.NET Framework 4.8.1
Method Categories Mean Ratio Gen0 Allocated Alloc Ratio
StakxRunningTaskT RunningTask<T> 6,797.09 ns 5.59 0.5798 3684 B 2.31
KunetRunningTaskT RunningTask<T> 1,215.56 ns 1.00 0.2537 1597 B 1.00
StakxRunningValueTaskT RunningValueTask<T> 7,117.17 ns 5.67 0.5951 3755 B 2.24
KunetRunningValueTaskT RunningValueTask<T> 1,254.33 ns 1.00 0.2651 1677 B 1.00
StakxTask Task 3,158.44 ns 65.02 0.1793 1140 B 6.16
KunetTask Task 48.58 ns 1.00 0.0293 185 B 1.00
StakxTaskT Task<T> 4,347.93 ns 8.71 0.3281 2071 B 2.63
KunetTaskT Task<T> 499.03 ns 1.00 0.1249 786 B 1.00
StakxValueTask ValueTask 3,612.61 ns 67.68 0.2022 1276 B 5.12
KunetValueTask ValueTask 53.37 ns 1.00 0.0395 249 B 1.00
StakxValueTaskT ValueTask<T> 4,596.25 ns 8.52 0.3204 2055 B 2.67
KunetValueTaskT ValueTask<T> 539.78 ns 1.00 0.1221 770 B 1.00
StakxVoid Void 1,111.00 ns 32.64 0.0515 329 B 3.16
KunetVoid Void 34.04 ns 1.00 0.0166 104 B 1.00
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 249 6/13/2025
2.0.0 172 5/11/2025
1.1.0 168 7/8/2024