Grace
Grace copied to clipboard
Intercept Async Methods, IInterceptor vs IAsyncInterceptor
I've been using Grace for some time. Thanks! It has been working really well.
I've been implementing IInterceptor, but as our code gets more and more async, I'm finding that this isn't working. I'm using Castle.Core for interception.
Someone has written an extension for Castle.Core to help simplify Async Interception. Castle.Core.AsyncInterceptor. The type I'm using is IAsyncInterceptor, as mentioned in Option 2.
In order for this to work, there needs to be some support in Grace for the new interface, IAsyncInterceptor.
So 2 questions I guess.
- Is there a currently supported way to handle intercepting Async and Synchronous Methods? (example?)
- If not, would it be possible to support IAsyncInterceptor in Grace?
Thanks,
Sean
@ipjohnson Could this be a limitation due to the lack of async support in LINQ expressions (Expression
)? Seeing as System.Linq.Expressions
have been archived this doesn't look very promising.
https://github.com/dotnet/csharplang/discussions/158 https://github.com/dotnet/runtime/issues/27790
@silkfire is correct that Grace itself can not have async parts in dependency construction.
That said Grace doesn't do any interception itself so it should be possible to plug in any interception library be it sync or async.
What specifically isn't work?
Good question. I guess I've been using it so long I forgot who owns the interception code.
I'm using (an old copy, I just noticed) of this InterceptionExtensions to hook up interception.
It doesn't support the new IAsyncInterceptor interface. Now that I realize where that came from, I can understand your confusion!
InterceptionHandler class implements IAsyncInterceptor. It used to implement IInteceptor.
exportRegistrationBlock.Intercept<InterceptionHandler>(interceptInterface);
The constraint on this is for IInterceptor. I guess I need to spend some time on this code, see if I can get it working with IAsyncInterceptor.
I may need some help if I get stuck.
Thanks,
Sean
Let me know if you run into any trouble, my hope is that it's pretty straight forward.