This guide registers the context-aware client in a .NET 10 application and reads recently modified customers.
dotnet add package DevOp.DK.Plus
DevOp.ERP.Abstractions is installed automatically.
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);
Only ApiToken is required. The client owns its secure pooled HTTP transport and must be disposed. Reuse it for related operations instead of creating one client for every request. Dependency injection remains recommended for ASP.NET Core and multitenant applications.
using DevOp.DK.Plus;
using DevOp.DK.Plus.Extensions;
services.AddDkPlus();
services.AddScoped<IDkPlusContextProvider, ApplicationDkPlusContextProvider>();
services.AddScoped<IDkPlusTokenProvider, DatabaseDkPlusTokenProvider>();
The application supplies:
IDkPlusContextProvider, which returns the current immutable tenant/company/optional-user context;IDkPlusTokenProvider, which asynchronously retrieves the authorized credential from the application's database or secret store.The library does not depend on an ORM, database, ASP.NET Core, or IHttpContextAccessor.
A credential provider returns:
return new DkPlusCredentials(decryptedToken);
The API URL defaults to https://api.dkplus.is. Supply a different URL only when an application endpoint policy explicitly permits it.
using DevOp.ERP;
using DevOp.ERP.Models;
public sealed class RecentCustomerReader(IExternalErpClient erp)
{
public Task<IReadOnlyList<Customer>> ReadAsync(
CancellationToken cancellationToken) =>
erp.Customer.Query()
.ModifiedSince(DateTimeOffset.UtcNow.AddDays(-1))
.Take(100)
.ToListAsync(cancellationToken);
}
The service never retrieves tokens, creates an HTTP client, or configures authorization headers. Credentials are resolved for each operation and applied only to that request.
For a simple application with one startup-known token, only ApiToken is required:
{
"DkPlus": {
"ApiToken": "set-through-a-secret-provider"
}
}
services.AddDkPlusClient(configuration, "DkPlus");
Base URL, versioned user agent, UI language, timeout, page size, and retry settings all have defaults.
Inject IDkPlusClient for DK Plus-only operations:
public sealed class InvoiceDocumentReader(IDkPlusClient dkPlus)
{
public Task<byte[]> DownloadAsync(
string invoiceNumber,
CancellationToken cancellationToken) =>
dkPlus.Sales.Invoice.GetPdfAsync(
invoiceNumber,
cancellationToken: cancellationToken);
}
Request DTOs are recursively validated before network I/O. Model labels support English and Icelandic through resource-backed DisplayAttribute metadata, while the API language follows the current UI culture unless explicitly configured.
See Request model validation and Localization and globalization.
Next: Configuration or Multitenancy