How do I override the async methods for sending a request in OData-client v7 using Blazor WASM?

Viewed 12

I am trying to ensure that a token exists when sending a request using Microsoft.Odata.Client v7 in Blazor WebAssembly. I am aware the DataServiceContext contains a SendingRequest2, but this is synchronous. The problem is that Blazor does not like to use wait monitors, so waiting for a task to finish in this event will not work. I want to ensure a token exists and is valid, and otherwise get a new token when a request is made. I want to make sure the client contains this behaviour, rather than creating a wrapper method that does this. This ensures the behaviour is not forgotten by accident in the future, and is cleaner in general.

DataServiceContext contains many virtual methods that can be overidden, but I could not figure out which one should be used (I debugged this by logging a message in all of them. None appeared).

DataServiceQuery also has methods that can be overidden, and I in fact use these. But I can not override these with a new class as I am unable to create an inherited class due to the fact that there is no documentation on how to manually create a DataServiceQuery. Normally you would use DataServiceContext's CreateQuery method for this, but this will not work with inherited classes. Making your own variant requires arguments that are not accessible as far as I found out.

Does anybody know how I can add custom asynchronous behaviour to sending requests with OData Client?

0 Answers
Related