TaskHub.Shared

TaskHub.Shared.Networking.Implementation

Declarative configuration and registration of resilient HTTP clients.

Contents

Summary


TaskHub.Shared.Networking provides a centralized and declarative approach to configuring HTTP communication using the HttpClientFactory and Polly.

Core Idea

The module addresses common networking concerns:

Configuration

Networking configuration is built around two concepts:

AppSettings Example

"Networking": {
    "Defaults": {
      "RetryCount": 3,
      "TimeoutInMilliseconds": 5000,
      "RetryDelayInMilliseconds": 100,
      "RetryStrategy": "Exponential",
      "UserAgent": "TaskHub-Client"
    },
    "Services": {
      "Google": {
        "BaseUrl": "https://google.com"
      }
    }
}

Dependency Injection

Register the networking settings in your Program.cs:

builder.Services.AddAppNetworkingSettings(builder.Configuration.GetSection("Networking").Bind);

Usage

Inject IHttpClientFactory to obtain a configured client:

public class MyService(IHttpClientFactory factory)
{
    private readonly HttpClient client = factory.CreateClient("Google");
}