I am using the service ITADService with the following method:
public async Task GetAllGames()
{
var result = InterpretStringResponse((await _http.GetAsync("api/itad")).ToString());
}
My razor page calls this method with:
protected override async Task OnInitializedAsync()
{
await ITADService.GetAllGames();
}
This leads to the CS0120 build-time error stating that an object reference is necessary, yet when I create an instance of the service on the page with:
private readonly HttpClient _http;
ITADService service = new ITADService(_http);
Visual Studio tells me that an initializer cannot reference it if it isn't static.
How is this supposed to be done? Is the error in the service or the page?
How is this supposed to be done?
builder.Services.RegisterScoped<ITADService>();
public ITADService(HttpClient http) { _http = http; }
@inject ITADService iTADService
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With