Bedingung vom Typ new() entfernen

This commit is contained in:
Developer 02 2024-06-27 16:02:41 +02:00
parent 8f09ec4255
commit b0f5738390
7 changed files with 10 additions and 7 deletions

View File

@ -1,7 +1,6 @@
namespace DigitalData.Core.Abstractions.Client
{
public interface IHttpClientService<TClientOptions> : IBaseHttpClientService
where TClientOptions : new()
{
}
}

View File

@ -18,7 +18,7 @@
<PackAsTool>False</PackAsTool>
<NeutralLanguage>aa-DJ</NeutralLanguage>
<PackageIcon>Assets\icon.png</PackageIcon>
<Version>1.0.1</Version>
<Version>1.0.1.1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -18,7 +18,7 @@ namespace DigitalData.Core.Client
}
public static IServiceCollection AddHttpClientService<TClientOptions>(this IServiceCollection services, Action<TClientOptions>? clientOptions = null, bool setAsDefaultBase = false)
where TClientOptions : HttpClientOptions, new()
where TClientOptions : HttpClientOptions
{
services.TryAddSingleton<HttpClient>();
services.TryAddSingleton<CookieContainer>();

View File

@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<Description>This package provides HTTP client extension methods for the DigitalData.Core library, offering simplified and asynchronous methods for fetching and handling HTTP responses. It includes utility methods for sending GET requests, reading response content as text or JSON, and deserializing JSON into dynamic or strongly-typed objects using Newtonsoft.Json. These extensions facilitate efficient and easy-to-read HTTP interactions in client applications.</Description>
<PackageId>DigitalData.Core.Client</PackageId>
<Version>1.0.1</Version>
<Version>1.0.1.1</Version>
<Authors>Digital Data GmbH</Authors>
<Company>Digital Data GmbH</Company>
<Product>Digital Data GmbH</Product>

View File

@ -2,6 +2,6 @@
{
public class HttpClientOptions
{
public required string Uri { get; set; }
public string Uri { get; set; } = string.Empty;
}
}

View File

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

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using DigitalData.Core.Abstractions.Client;
using Microsoft.Extensions.DependencyInjection;
namespace DigitalData.Core.Client
{
@ -17,5 +18,8 @@ namespace DigitalData.Core.Client
private static IServiceProvider Build() => _services.BuildServiceProvider();
public static T Provide<T>() where T : notnull => _lazyProvider.Value.GetRequiredService<T>();
public static IHttpClientService<TOptions> ProvideHttpClientService<TOptions>() where TOptions : notnull
=> _lazyProvider.Value.GetRequiredService<IHttpClientService<TOptions>>();
}
}