Files
DocumentService/DocumentService.Client/Extensions/ServiceCollectionExtensions.cs
TekH 0c27e4fd91 Add WorkflowsClient for PDF validation and QR extraction
Introduced a new `WorkflowsClient` to orchestrate multi-step
operations, combining `IPdfValidationClient` and
`ISwissQrCodeClient`. Added methods to validate PDFs and extract
Swiss QR Codes in a single call, with overloads for byte arrays,
streams, and file paths. Registered `WorkflowsClient` as a scoped
service in `ServiceCollectionExtensions`.

Updated `PdfValidationResult` with an `IsValid` property to
simplify PDF validity checks. Added `IWorkflowsClient` interface
to define the contract for the new client, with detailed XML
documentation for its methods.
2026-08-31 03:21:41 +02:00

68 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using DocumentService.Client.Clients;
using DocumentService.Client.Configuration;
using DocumentService.Client.Interfaces;
using Microsoft.Extensions.DependencyInjection;
using System.Net;
using System.Net.Http;
namespace DocumentService.Client.Extensions;
/// <summary>
/// Extension methods for registering DocumentService clients in DI container.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Registers all six DocumentService HTTP clients as Scoped via HttpClientFactory.
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="configureOptions">Configuration action for client options</param>
/// <returns>Service collection for chaining</returns>
public static IServiceCollection AddDocumentServiceClients(
this IServiceCollection services,
Action<DocumentServiceClientOptions> configureOptions)
{
services.Configure(configureOptions);
var options = new DocumentServiceClientOptions();
configureOptions(options);
var configureHandler = () => new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};
void ConfigureClient(System.Net.Http.HttpClient client)
{
client.BaseAddress = new Uri(options.BaseUrl);
client.Timeout = options.Timeout;
}
services.AddHttpClient<IPdfValidationClient, PdfValidationClient>(ConfigureClient)
.ConfigurePrimaryHttpMessageHandler(configureHandler);
services.AddHttpClient<IPdfAttachmentClient, PdfAttachmentClient>(ConfigureClient)
.ConfigurePrimaryHttpMessageHandler(configureHandler);
services.AddHttpClient<IPdfOperationsClient, PdfOperationsClient>(ConfigureClient)
.ConfigurePrimaryHttpMessageHandler(configureHandler);
services.AddHttpClient<ISwissQrCodeClient, SwissQrCodeClient>(ConfigureClient)
.ConfigurePrimaryHttpMessageHandler(configureHandler);
services.AddHttpClient<IZugferdClient, ZugferdClient>(ConfigureClient)
.ConfigurePrimaryHttpMessageHandler(configureHandler);
// Conversion client is registered but all methods throw NotImplementedException
// until the server-side endpoints are ready.
services.AddHttpClient<IPdfConversionClient, PdfConversionClient>(ConfigureClient)
.ConfigurePrimaryHttpMessageHandler(configureHandler);
// WorkflowsClient composes existing clients – no HttpClient needed.
services.AddScoped<IWorkflowsClient, WorkflowsClient>();
return services;
}
}