Verbinde HttpClient mit ClientOptions
This commit is contained in:
parent
8c6719f516
commit
fe198615fc
@ -1,5 +1,7 @@
|
|||||||
using Leanetec.EConnect.Client.Interface;
|
using Leanetec.EConnect.Client;
|
||||||
|
using Leanetec.EConnect.Client.Interface;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Leanetec.EConnect.Infrastructure;
|
namespace Leanetec.EConnect.Infrastructure;
|
||||||
|
|
||||||
@ -9,7 +11,19 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
internal static IServiceCollection ConfigureEConnectClient(this IServiceCollection services, Action<HttpClient> configureClient)
|
internal static IServiceCollection ConfigureEConnectClient(this IServiceCollection services, Action<HttpClient> configureClient)
|
||||||
{
|
{
|
||||||
services.AddHttpClient(EConnectClientName, configureClient);
|
services.AddHttpClient(EConnectClientName, (provider, client) => {
|
||||||
|
var opt = provider.GetRequiredService<IOptions<ClientOptions>>().Value;
|
||||||
|
|
||||||
|
// add common parameters
|
||||||
|
if (opt.BaseAddress is string baseAddress)
|
||||||
|
client.BaseAddress = new Uri(baseAddress);
|
||||||
|
|
||||||
|
if (opt.Timeout is TimeSpan timeout)
|
||||||
|
client.Timeout = timeout;
|
||||||
|
|
||||||
|
// add spesific (library based) parameters
|
||||||
|
configureClient(client);
|
||||||
|
});
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user