Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add memento capture to IInvocation (aka async interception groundwork) #438

Closed
wants to merge 3 commits into from

Conversation

stakx
Copy link
Member

@stakx stakx commented Mar 23, 2019

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 an await), interception starts to regress back to the caller and the invocation's currentInterceptorIndex starts getting decremented—this is why invocation.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 (and currentInterceptorIndex with it) from AbstractInvocation would possibly be the cleaner solution in the long term, it would also trigger the need for a fairly large breaking change in DynamicProxy's Intercept / 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

JSkimming and others added 3 commits March 21, 2019 19:32
This is a sneaky way of making `AbstractInvocation.currentInterceptor-
Index` modifiable without exposing it.
@stakx
Copy link
Member Author

stakx commented Mar 24, 2019

Closing for the time being... while this doesn't expose AbstractInvocation.currentInterceptorIndex, it still makes it possible to mess around with internals that noone should ever notice. I think I can do one better.

@stakx stakx closed this Mar 24, 2019
@stakx stakx deleted the invocation-memento branch August 12, 2019 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants