Add memento capture to IInvocation
(aka async interception groundwork)
#438
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the smallest change I can think of that might just be sufficient to enable people to write async interceptors. While technically still a breaking change (it adds a new member to the pre-existing
IInvocation
interface) it's a comparatively minor one, and it does fix the same unit test from #429.What problem does this PR attempt to solve? As soon as an async continuation is set up in an interceptor's
Intercept
method (e.g. by means of anawait
), interception starts to regress back to the caller and the invocation'scurrentInterceptorIndex
starts getting decremented—this is whyinvocation.Proceed()
will no longer work in the async continuations: it will end up proceeding to an earlier interceptor instead of to the next one.I therefore tried to find a way to make
currentInterceptorIndex
modifiable without exposing it, and ended up with the Memento pattern.While I think completely removing
Proceed
(andcurrentInterceptorIndex
with it) fromAbstractInvocation
would possibly be the cleaner solution in the long term, it would also trigger the need for a fairly large breaking change in DynamicProxy'sIntercept
/Proceed
API, and I'm not sure we're ready for that.I don't expect this to get merged, as we probably don't really need a generic memento facility for invocation objects 😜, but I am still curious what others think about this approach.
/cc @JSkimming, @brunoblank