Is there any issue with below implementation inside Blazor component? A lot of examples repeatedly use CreateClient inside every method and I am wondering if it can be handled by a property, in one place to avoid repetition.
@inject IHttpClientFactory ClientFactory
@code{
private HttpClient Client => ClientFactory.CreateClient("api");
private object myData;
private async Task GetData()
{
myData = await Client.GetFromJsonAsync<MyClass>("endpoint");
}
}
MyClass.