Yesterday I blogged about using Castle.DynamicProxy to generate a proxy class and use AOP techniques for caching. The code I showed worked for synchronous method calls but fails when you want to proxy async method calls.
Let’s see how we can get this working for async…
Here is the async version of our repository:
We need an extra NuGet package:
dotnet add Castle.Core.AsyncInterceptor
Now we have to change our interceptor to call a second async interceptor:
Our extension method that triggers the proxy creation remains the same:
Our registration code should be extended to register the async interceptor as well: