Declarative configuration and registration of resilient HTTP clients.
HttpClients.TaskHub.Shared.Networking provides a centralized and declarative approach to configuring HTTP communication using the HttpClientFactory and Polly.
The module addresses common networking concerns:
Networking configuration is built around two concepts:
"Networking": {
"Defaults": {
"RetryCount": 3,
"TimeoutInMilliseconds": 5000,
"RetryDelayInMilliseconds": 100,
"RetryStrategy": "Exponential",
"UserAgent": "TaskHub-Client"
},
"Services": {
"Google": {
"BaseUrl": "https://google.com"
}
}
}
Register the networking settings in your Program.cs:
builder.Services.AddAppNetworkingSettings(builder.Configuration.GetSection("Networking").Bind);
Inject IHttpClientFactory to obtain a configured client:
public class MyService(IHttpClientFactory factory)
{
private readonly HttpClient client = factory.CreateClient("Google");
}