Replaced direct injection of HttpClient with IHttpClientFactory across the codebase to improve HTTP client management and align with best practices. Removed dependency on ApiOptions and IOptions<ApiOptions> in multiple services, simplifying constructors and reducing configuration complexity. Updated FontLoader to use IHttpClientFactory for font loading with relative paths. Adjusted comments and documentation to reflect these changes. Cleaned up unused using directives related to ApiOptions.
25 lines
1020 B
C#
25 lines
1020 B
C#
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using EnvelopeGenerator.Server.Client.Models;
|
|
|
|
namespace EnvelopeGenerator.Server.Client.Services;
|
|
|
|
public class SignatureService(IHttpClientFactory httpClientFactory)
|
|
{
|
|
private static readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerDefaults.Web);
|
|
|
|
public async Task<IReadOnlyList<SignatureDto>> GetAsync(string envelopeKey, CancellationToken cancel = default)
|
|
{
|
|
using var http = httpClientFactory.CreateClient("EnvelopeGenerator.Server");
|
|
var url = $"/api/Signature/{Uri.EscapeDataString(envelopeKey)}";
|
|
var response = await http.GetAsync(url, cancel);
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
throw new HttpRequestException($"Failed to retrieve signatures for envelope {envelopeKey}: {response.StatusCode} {response.ReasonPhrase}");
|
|
|
|
var result = await response.Content.ReadFromJsonAsync<List<SignatureDto>>(_jsonOptions, cancel);
|
|
return result ?? [];
|
|
}
|
|
}
|