fix(Client.DIExtensions): Generischer Typ zur Injektion mehrerer Client-Dienste hinzugefügt

This commit is contained in:
Developer 02 2024-11-25 10:58:45 +01:00
parent ea3d1312b8
commit 52a7664e57
3 changed files with 4 additions and 4 deletions

View File

@ -1,5 +1,4 @@
using DigitalData.Core.Abstractions.Client;
using Microsoft.Extensions.Options;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Web;

View File

@ -8,13 +8,14 @@ namespace DigitalData.Core.Client
{
public static class DIExtensions
{
public static IServiceCollection AddHttpClientService(this IServiceCollection services, IConfigurationSection? section = null)
public static IServiceCollection AddHttpClientService<THttpClientOptions>(this IServiceCollection services, IConfigurationSection? section = null)
where THttpClientOptions : HttpClientOptions
{
services.TryAddSingleton<HttpClient>();
services.TryAddSingleton<CookieContainer>();
services.TryAddSingleton<IBaseHttpClientService, BaseHttpClientService>();
if(section is not null)
services.Configure<HttpClientOptions>(section);
services.Configure<THttpClientOptions>(section);
return services;
}

View File

@ -7,7 +7,7 @@ namespace DigitalData.Core.Client
public class HttpClientService<TClientOptions> : BaseHttpClientService, IHttpClientService<TClientOptions>, IBaseHttpClientService
where TClientOptions : HttpClientOptions
{
public HttpClientService(HttpClient client, CookieContainer cookieContainer, IOptions<TClientOptions> clientOptions) : base(client, cookieContainer, clientOptions)
public HttpClientService(HttpClient client, CookieContainer cookieContainer, IOptions<TClientOptions> clientOptions) : base(client, cookieContainer, clientOptions.Value)
{
}
}