feat(IHttpClientOptions):

Basispfad zu http-Client-Optionen hinzugefügt
This commit is contained in:
Developer 02
2024-11-22 12:05:13 +01:00
parent c3a12ba5b7
commit bd4d4856ea
6 changed files with 29 additions and 14 deletions

View File

@@ -7,12 +7,16 @@ namespace DigitalData.Core.Client
{
public static class DIExtensions
{
public static IServiceCollection AddHttpClientService(this IServiceCollection services, string uri)
public static IServiceCollection AddHttpClientService(this IServiceCollection services, string uri, string path = "")
{
services.TryAddSingleton<HttpClient>();
services.TryAddSingleton<CookieContainer>();
services.AddSingleton<IBaseHttpClientService, BaseHttpClientService>();
services.Configure<HttpClientOptions>(opt => opt.Uri = uri);
services.Configure<HttpClientOptions>(opt =>
{
opt.Uri = uri;
opt.Path = path;
});
return services;
}
@@ -22,11 +26,11 @@ namespace DigitalData.Core.Client
{
services.TryAddSingleton<HttpClient>();
services.TryAddSingleton<CookieContainer>();
services.AddSingleton<IHttpClientService<TClientOptions>, HttpClientService<TClientOptions>>();
services.TryAddSingleton<IHttpClientService<TClientOptions>, HttpClientService<TClientOptions>>();
services.Configure(clientOptions ?? (_ => { }));
if (setAsDefaultBase)
services.AddSingleton<IBaseHttpClientService, HttpClientService<TClientOptions>>();
services.TryAddSingleton<IBaseHttpClientService, HttpClientService<TClientOptions>>();
return services;
}