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:
OlgunR
2026-05-11 17:08:52 +02:00
parent 1b67d0472e
commit 45011122b2
4 changed files with 17 additions and 41 deletions

View File

@@ -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 ?? [];
}
}