mirror of
https://github.com/AlexMacocian/Net.Maui.Extensions.git
synced 2026-07-15 14:59:31 +00:00
Typed http client with resiliency
This commit is contained in:
@@ -3,7 +3,7 @@ using System.ComponentModel;
|
||||
using System.Core.Extensions;
|
||||
using System.Extensions;
|
||||
|
||||
namespace Net.Maui.Extensions.Extensions;
|
||||
namespace Net.Maui.Extensions;
|
||||
|
||||
public static class ContentPageExtensions
|
||||
{
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Core.Extensions;
|
||||
|
||||
namespace Net.Maui.Extensions.Extensions;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IHttpClientBuilder RegisterHttpClient<TService>(this IServiceCollection services)
|
||||
where TService : class
|
||||
{
|
||||
return services.ThrowIfNull()
|
||||
.AddScoped<IHttpClient<TService>, HttpClient<TService>>(sp =>
|
||||
{
|
||||
var factory = sp.GetRequiredService<IHttpClientFactory>();
|
||||
return new HttpClient<TService>(factory.CreateClient(typeof(TService).Name), false);
|
||||
})
|
||||
.AddHttpClient(typeof(TService).Name);
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>true</IsPackable>
|
||||
<Version>0.2.13</Version>
|
||||
<Version>0.3.0</Version>
|
||||
<Authors>Alexandru Macocian</Authors>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
@@ -46,6 +46,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CorrelationVector" Version="1.0.42" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.82" />
|
||||
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.82" />
|
||||
|
||||
Reference in New Issue
Block a user