Provides a cached HttpClient configured for the Docker Hub API and bearer authentication.
dotnet add package Soenneker.Docker.Hub.HttpClients{
"DockerHub": {
"AccessToken": "your-access-token"
}
}Keep the token in a secret provider rather than source control.
The transport can also be customized with these optional settings:
{
"Hub": {
"ClientBaseUrl": "https://hub.docker.com",
"AuthHeaderName": "Authorization",
"AuthHeaderValueTemplate": "Bearer {token}"
}
}The template replaces every literal {token} with DockerHub:AccessToken. Treat the base URL, header name, and template as trusted configuration because they determine where and how the credential is sent.
using Soenneker.Docker.Hub.HttpClients.Abstract;
using Soenneker.Docker.Hub.HttpClients.Registrars;
services.AddDockerHubOpenApiHttpClientAsSingleton();
public sealed class DockerHubTransport(IDockerHubOpenApiHttpClient clientProvider)
{
public async Task<HttpResponseMessage> Send(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
HttpClient client = await clientProvider.Get(cancellationToken);
return await client.SendAsync(request, cancellationToken);
}
}Get returns the cached client. Do not dispose the returned HttpClient; the registered provider owns the cache entry.
Singleton registration is the normal choice for direct transport use. AddDockerHubOpenApiHttpClientAsScoped() creates a separately owned cache entry for each scope, so disposing one provider cannot remove another provider's client.
This package only configures transport. It does not deserialize responses, paginate results, or convert non-success status codes into domain exceptions. Use the companion OpenAPI client utility when you want the generated Docker Hub API surface.