Dev.ExternalClients
0.1.0
dotnet add package Dev.ExternalClients --version 0.1.0
NuGet\Install-Package Dev.ExternalClients -Version 0.1.0
<PackageReference Include="Dev.ExternalClients" Version="0.1.0" />
<PackageVersion Include="Dev.ExternalClients" Version="0.1.0" />
<PackageReference Include="Dev.ExternalClients" />
paket add Dev.ExternalClients --version 0.1.0
#r "nuget: Dev.ExternalClients, 0.1.0"
#:package Dev.ExternalClients@0.1.0
#addin nuget:?package=Dev.ExternalClients&version=0.1.0
#tool nuget:?package=Dev.ExternalClients&version=0.1.0
external-clients
A .NET 9.0 library that provides configurable external HTTP client support. The library enables you to register and configure external HTTP clients via dependency injection (DI). You can configure clients either by providing an inline action or by binding to a section in your configuration (e.g., appsettings.json).
Project Structure
src/Dev.ExternalClients/
Contains the main library code:- ExternalClientOptions.cs – Defines configuration options for an external HTTP client, including properties for BaseAddress, Timeout, and DefaultRequestHeaders, and an
ApplyTomethod to configure anHttpClient. - ExternalClientServiceCollectionExtensions.cs – Provides extension methods to register external HTTP clients with DI. Supports inline configuration via an action and configuration binding from an
IConfigurationinstance.
- ExternalClientOptions.cs – Defines configuration options for an external HTTP client, including properties for BaseAddress, Timeout, and DefaultRequestHeaders, and an
tests/Dev.ExternalClients.Tests.Unit/
Contains unit tests that:- Verify that
ExternalClientOptionscorrectly configures anHttpClient. - Test various scenarios such as action-based configuration, configuration-based binding, multiple registrations, and different client setups.
- Verify that
Dev.ExternalClients.sln
The Visual Studio solution file which includes the library and tests.
Building the Project
Make sure you have the .NET 9.0 SDK installed on your Windows machine. From the repository root, run:
dotnet build
Running the Tests
You can run unit tests by executing:
dotnet test
Usage Examples
1. Inline Action Configuration
Register an external HTTP client with inline configuration in your application startup:
services.AddExternalClient<ITestClient, TestClient>(options =>
{
options.BaseAddress = "https://api.example.com";
options.Timeout = TimeSpan.FromSeconds(5);
options.DefaultRequestHeaders = new Dictionary<string, string>
{
{ "Authorization", "Bearer token" },
{ "Accept", "application/json" }
};
});
2. Binding from appsettings.json
Provide configuration in your appsettings.json and bind to a client options instance:
appsettings.json
{
"TestClient": {
"BaseAddress": "https://api.example.com",
"Timeout": "00:00:05",
"DefaultRequestHeaders": {
"Authorization": "Bearer token",
"Accept": "application/json"
}
}
}
Program.cs / Startup.cs
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Dev.ExternalClients;
var builder = WebApplication.CreateBuilder(args);
// Bind the TestClient section from appsettings.json to ExternalClientOptions.
builder.Services.Configure<ExternalClientOptions>(
builder.Configuration.GetSection("TestClient")
);
// Register the client using configuration binding.
builder.Services.AddExternalClient<ITestClient, TestClient>(
builder.Configuration
);
var app = builder.Build();
app.Run();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 187 | 2/23/2025 |