CustomAdaptor extending ODataV4Adaptor

Hi,

I am trying to create a customadapter simply to override ODataV4Adaptor's BeforeSend() to check if token is still valid before sending, i want to keep all other functionality in adaptor as is.
We already have an httpinterceptor for our applications but its not working with calls through the SfDataManager/ODataV4Adaptor..
My goal is to do this check with either a customadaptor or some kind of httpinterceptor for the adaptor wich i then can use in all of our applications.
But when im trying to use the customadapter i encountered some errors for example not being able to cast customadaptor to DataAdaptor.

1. Is it possible to create a CustomAdaptor by extending the ODataV4Adaptor or is it only possible with DataAdaptor?
2. If it is possible, how would i handle the ctor requiring DataManager, is it OK to inject? Is there any examples?
3. If it is NOT possible, do you have suggestions of another way i can solve my problem?

Regards,
Jesper

Using:
Syncfusion.Blazor 18.1.0.52
AspNetCore 3.1.4
AspNetCore.OData 7.4.0

1 Reply 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team August 17, 2020 07:28 AM UTC

Hi Jesper, 
 
Thanks for contacting Syncfusion support.  
 
Query: “I am trying to create a customadapter simply to override ODataV4Adaptor's BeforeSend() to check if token is still valid before sending, && If it is NOT possible, do you have suggestions of another way i can solve my problem? 
 
No, CustomAdaptor cannot be extended using ODataV4Adaptor, it will extend only DataAdaptor.  We have analyzed your query and we suspect that you want to send your Authentication Token to OData service to authorize the certain action. We suggest you to achieve your requirement by sending the Authentication token as header using Header property of SfDataManager.  
 
Refer the below code example 
 
<SfGrid TValue="Order" AllowPaging="true">  
    <SfDataManager Headers=@HeaderData Url="{url}" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>  
    <GridColumns>  
. . . . . . .. .  
    </GridColumns>  
</SfGrid>  
  
@code{  
    private IDictionary<stringstring> HeaderData = new Dictionary<stringstring>();  
  
    protected override void OnInitialized()  
    {  
        HeaderData.Add("Bearer""{your_auth_token}");  
    }  
  
    public class Order  
    {  
        public int? OrderID { getset; }  
        public string CustomerID { getset; }  
        public DateTime? OrderDate { getset; }  
        public double? Freight { getset; }  
    }  
}  
 
Refer our UG documentation for your reference 
 
 
Please get back to us if you have further queries.  
  
Regards, 
Vignesh Natarajan  
 


Marked as answer
Loader.
Up arrow icon