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

DOCS Suggestion, add more extensive docs for delegating handlers as its tricky in F# #226

Open
jkone27 opened this issue Apr 24, 2023 · 3 comments

Comments

@jkone27
Copy link
Contributor

jkone27 commented Apr 24, 2023

Without having this, I had bugs in my delegating handlers when adding e.g. authorization to query

https://gist.github.com/panesofglass/a1cfc3c9a3f0d41233ad

the reason is that if just using base.SendAsync inside a task { .. } or async { ... } ce, it will fail to update the parameters and execute it in a different order. I was just assigning it to a binding outside the task and then executing it within the task but that was wrong, it only works if there is no mutation e.g. of request or response.

Shall we add this info to docs website?

@sergey-tihon
Copy link
Member

Not sure that I fully understand

Here is current auth doc
https://fsprojects.github.io/SwaggerProvider/#/Customization#authentication

and for sure you need to modify request before you call SendAsync (not matter you use task/async ce or not).

your sample should work like if you change it like this

let loggingHandler =
    { new DelegatingHandler() with
        member x.SendAsync(request, cancellationToken) = 
            task {
                 // your code here, if you change Request it will not change! beware !!!!!
                 return! base.SendAsync(request, cancellationToken)
            }
    }

what you propose to improve?

@jkone27
Copy link
Contributor Author

jkone27 commented May 5, 2023

mmm.. if you call base.SendAsync inside the task, the F# compiler will complain dotnet/fsharp#12448

@sergey-tihon
Copy link
Member

sergey-tihon commented May 5, 2023

It is slightly surprising, but issue that you mentioned also contains workaround that can be used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants