TaskHub.Shared.Networking module provides a centralized and declarative approach to configuring HTTP communication between services.
The module addresses common networking concerns in microservice-based systems:
Networking configuration is built around two concepts:
NetworkDefaults define the baseline networking policy applied to all outbound HTTP requests. Use defaults to express system-wide expectations, not service-specific behavior. Options:
NetworkNode represents an individual remote service with its own configuration.
All retry, timeout, user-agent, and retry-strategy properties have the same meaning as in NetworkDefaults and act as per-node overrides.
Below are only the properties that do not exist in NetworkDefaults:
Networking settings are defined in the appsettings.json file under the Networking section.
example:
"Networking": {
"Defaults": {
"RetryCount": 3,
"TimeoutInMilliseconds": 5000,
"RetryDelayInMilliseconds": 100,
"RetryStrategy": "Exponential",
"UserAgent": "TaskHub-Offer"
},
"Services": {
"Google": {
"BaseUrl": "https://google.com"
}
}
}
To use the TaskHub.Shared.Networking module, register it in the dependency injection container:
builder.Services.AddAppNetworkingSettings(Builder.Configuration.GetSection("Networking").Bind);
This registers configured HttpClients for each defined NetworkNode, applying global defaults and per-node overrides.
Inject IHttpClientFactory into your services to obtain configured HttpClients:
public class MyService(IHttpClientFactory _httpClientFactory)
{
private readonly HttpClient Client = _httpClientFactory.CreateClient("Google");
}