Refactor API clients to use primary constructor for HttpClient
Refactored CatalogApiClient, DashboardApiClient, LayoutApiClient, and MassDataApiClient to use C# primary constructor syntax for injecting HttpClient. Removed private _httpClient fields and updated all usages to reference the constructor parameter directly. This change simplifies the code and modernizes dependency injection without altering any API logic.
This commit is contained in:
@@ -2,19 +2,13 @@ using DbFirst.Contracts.Dashboards;
|
||||
|
||||
namespace DbFirst.BlazorWebApp.Services;
|
||||
|
||||
public class DashboardApiClient : IDashboardApiClient
|
||||
public class DashboardApiClient(HttpClient httpClient) : IDashboardApiClient
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private const string Endpoint = "api/dashboard/dashboards";
|
||||
|
||||
public DashboardApiClient(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
|
||||
public async Task<List<DashboardInfoDto>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
var result = await _httpClient.GetFromJsonAsync<List<DashboardInfoDto>>(Endpoint, ct);
|
||||
var result = await httpClient.GetFromJsonAsync<List<DashboardInfoDto>>(Endpoint, ct);
|
||||
return result ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user