Console applications, desktop applications, tests, and small integrations can create one long-lived client directly:
using var client = DkPlusClient.Create(new DkPlusClientOptions
{
ApiToken = token
});
var company = await client.Company.GetSettingsAsync(cancellationToken);
The returned DkPlusClient owns its HttpClient, resilience handler, and pooled transport, so it must be disposed. Reuse it for related operations rather than creating a client per request. The transport disables redirects and cookies, refreshes pooled connections every ten minutes, and applies the standard resilience profile only to eligible safe methods.
Logging is optional. Supply a caller-owned logger factory when diagnostics are required:
using var client = DkPlusClient.Create(options, loggerFactory);
The client never disposes the supplied logger factory. The lower-level public constructor remains available for advanced callers that supply a fully configured HttpClient; in that case the caller owns and disposes that HttpClient.
Use the provider-based registration for multitenant applications:
services.AddDkPlus();
services.AddScoped<IDkPlusContextProvider, ApplicationDkPlusContextProvider>();
services.AddScoped<IDkPlusTokenProvider, DatabaseDkPlusTokenProvider>();
No DK Plus token is stored in package configuration. IDkPlusTokenProvider returns a DkPlusCredentials object for each operation. Its BaseUrl defaults to https://api.dkplus.is and only needs to be supplied for an intentional endpoint override.
AddDkPlus accepts optional non-secret behavior overrides:
services.AddDkPlus(options =>
{
options.PageSize = 250;
options.Resilience.MaxRetryAttempts = 2;
});
For a single startup-known token, only ApiToken is required:
{
"DkPlus": {
"ApiToken": "set-through-a-secret-provider"
}
}
services.AddDkPlusClient(configuration, "DkPlus");
Do not commit the real token. Bind it from an environment variable, deployment secret, or .NET user secrets.
Every other setting has a default and can be omitted:
| Setting | Default |
|---|---|
BaseUrl |
https://api.dkplus.is |
UserAgent |
DevOp-DK-Client/<package-version> |
AcceptLanguage |
CultureInfo.CurrentUICulture, or en for invariant culture |
PageSize |
100 |
Resilience.MaxRetryAttempts |
3 |
Resilience.RetryDelay |
500 milliseconds |
Resilience.RetryMaxDelay |
5 seconds |
Resilience.BackoffType |
Exponential |
Resilience.UseJitter |
true |
Resilience.AttemptTimeout |
10 seconds |
Resilience.TotalRequestTimeout |
30 seconds |
Resilience.CircuitBreakerFailureRatio |
0.1 |
Resilience.CircuitBreakerMinimumThroughput |
10 |
Resilience.CircuitBreakerSamplingDuration |
30 seconds |
Resilience.CircuitBreakerBreakDuration |
5 seconds |
An override configuration can therefore include only the values that differ:
{
"DkPlus": {
"ApiToken": "set-through-a-secret-provider",
"BaseUrl": "https://approved-alternate-endpoint.example",
"AcceptLanguage": "is-IS",
"PageSize": 250,
"Resilience": {
"MaxRetryAttempts": 2,
"TotalRequestTimeout": "00:00:20"
}
}
}
The package automatically sends:
User-Agent: DevOp-DK-Client/<version>
The CLI sends DevOp-DK-CLI/<version>. Normal consumers do not need to configure UserAgent; an explicit override remains available for an application-specific HTTP product identifier.
An Icelandic UI locale or explicit is-IS preference produces:
Accept-Language: is-IS, en;q=0.8
Provide one language tag only. The client owns the English fallback and quality value.
The package validates endpoints, HTTP product identity, language, page size, retry, timeout, circuit-breaker, and pooled connection-lifetime settings. Static registrations additionally require an API token. Contextual registrations validate credentials and the endpoint policy for every operation.
RetryCount, RetryDelay, RetryMaxDelay, and Timeout remain compatibility aliases for the nested resilience settings. Prefer Resilience in new configuration. See HTTP resilience for behavior and Multi-tenant context and credential resolution for database providers, explicit job contexts, endpoint policies, credential caching, and refresh guidance.