Is there any other way of injecting a service into a Blazor component other than the [Inject} method?

Answer:

We suspect that you are using CustomAdaptor to bind data to Grid. Based on your query, we suggest you to use constructor injection instead of using [Inject] inside the CustomAdaptor class. Please refer and use the below highlighted codes in your application to inject services through Constructor injection in CustomAdaptor instead of using [Inject].

public class CustomAdaptor : DataAdaptor

{

public WeatherForecastService WeatherForecastService { get; set; }

public MyDataAdaptor(WeatherForecastService weatherForecastService)

{

WeatherForecastService = weatherForecastService;

}

public override async Task<object> ReadAsync(DataManagerRequest dataManagerRequest, string key = null)

{

...

}

}

Here is the documentation for your reference,

https://blazor.syncfusion.com/documentation/datagrid/custom-binding/#inject-service-into-custom-adaptor


Loader.
Up arrow icon