Updated DependencyInjection.cs to change ISmsSender and IEnvelopeSmsHandler lifetimes from Singleton to Scoped, ensuring per-request instantiation. Added Microsoft.Extensions.Http package to EnvelopeGenerator.Server.Client.csproj for enhanced HttpClient handling. Refactored AnnotationService, AuthService, DocumentService, EnvelopeReceiverService, SignatureCacheService, and SignatureService to use IHttpClientFactory, improving flexibility and testability. Introduced a named HttpClient "EnvelopeGenerator.Server" in Program.cs for internal API calls, and removed the previous HttpClient setup using HttpContextAccessor. Added necessary using directives for System.Net.Http across service files to support these changes.
27 lines
1.1 KiB
C#
27 lines
1.1 KiB
C#
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using EnvelopeGenerator.Server.Client.Models;
|
|
using EnvelopeGenerator.Server.Client.Options;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace EnvelopeGenerator.Server.Client.Services;
|
|
|
|
public class SignatureService(IHttpClientFactory httpClientFactory, IOptions<ApiOptions> apiOptions)
|
|
{
|
|
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 ?? [];
|
|
}
|
|
}
|