NewHeap.Platform.Common
2.0.0
dotnet add package NewHeap.Platform.Common --version 2.0.0
NuGet\Install-Package NewHeap.Platform.Common -Version 2.0.0
<PackageReference Include="NewHeap.Platform.Common" Version="2.0.0" />
<PackageVersion Include="NewHeap.Platform.Common" Version="2.0.0" />
<PackageReference Include="NewHeap.Platform.Common" />
paket add NewHeap.Platform.Common --version 2.0.0
#r "nuget: NewHeap.Platform.Common, 2.0.0"
#:package NewHeap.Platform.Common@2.0.0
#addin nuget:?package=NewHeap.Platform.Common&version=2.0.0
#tool nuget:?package=NewHeap.Platform.Common&version=2.0.0
NewHeap Platform Common
API clients
AddNhApiClient<TApi> registers a reusable client for one logical target API.
TApi is an empty marker type that lets related endpoint services share the
same base address, handlers, and token cache.
Registration can be performed directly in Program.cs:
builder.Services.AddNhApiClient<CommerceManagementApi>(options =>
{
options.BaseAddress = new Uri(
builder.Configuration["Commerce:ManagementApiUrl"]!);
});
Or from a configuration section:
builder.Services.AddNhApiClient<CommerceManagementApi>(
builder.Configuration.GetSection("ApiClients:CommerceManagement"));
{
"ApiClients": {
"CommerceManagement": {
"BaseAddress": "https://management.example.test",
"Timeout": "00:00:30"
}
}
}
An endpoint service derives from BaseNhApiService<TApi>:
public sealed class CommerceManagementApi;
public sealed class OperationsUserApiService
: BaseNhApiService<CommerceManagementApi>
{
public OperationsUserApiService(
ILogger<OperationsUserApiService> logger,
INhApiHttpClientFactory<CommerceManagementApi> httpClientFactory)
: base(logger, httpClientFactory)
{
}
public Task<TaskResult<OperationsUserViewModel>> GetAsync(
Guid id,
CancellationToken cancellationToken = default)
{
return DoGetAsync<OperationsUserViewModel>(
$"/api/management/operations-user/{id}",
cancellationToken);
}
}
The base class provides helpers for GET, collection GET, POST, PUT, PATCH, and
DELETE. Every helper has a default implementation and is protected virtual.
JSON responses and NewHeap validation errors are returned as TaskResult.
Downloads and raw responses
Use DoGetResponseAsync when content must not be buffered as JSON. The result
owns the response, request, and factory client, so it must be disposed:
public async Task<TaskResult> DownloadAsync(
Stream destination,
CancellationToken cancellationToken = default)
{
using var responseResult = await DoGetResponseAsync(
"/api/management/export",
cancellationToken);
if (!responseResult.Success)
{
return TaskResult.Failed(responseResult);
}
await using var source = await responseResult.Data.ReadAsStreamAsync(cancellationToken);
await source.CopyToAsync(destination, cancellationToken);
return TaskResult.Succeeded();
}
For other HTTP methods, the same raw pipeline is available through
DoSendResponseAsync. Regular DTO methods deliberately remain TaskResult<T>.
Username and password authentication
When Authentication is present, the library automatically registers a
separate authentication client, bearer handler, and thread-safe token cache:
{
"ApiClients": {
"CommerceManagement": {
"BaseAddress": "https://management.example.test",
"Authentication": {
"Endpoint": "/api/authentication/username-password",
"Username": "service-account",
"Password": "configure-via-user-secrets-or-environment",
"Realm": "",
"RefreshBeforeExpiration": "00:03:00"
}
}
}
}
Do not store passwords in a committed appsettings.json; use user secrets,
environment variables, or a secret store. For other authentication methods, a
custom INhApiAccessTokenProvider<TApi> can be registered through
AddNhApiClient<TApi, TAccessTokenProvider>().
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- AutoMapper (>= 14.0.0)
- Hangfire (>= 1.8.23)
- Hangfire.Console (>= 1.4.3)
- KeyedSemaphores (>= 6.1.0)
- Microsoft.EntityFrameworkCore (>= 10.0.10)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.ServiceDiscovery (>= 10.8.0)
- Newtonsoft.Json (>= 13.0.4)
- OpenTelemetry (>= 1.16.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.16.0)
- OpenTelemetry.Extensions.Hosting (>= 1.16.0)
- OpenTelemetry.Instrumentation.Runtime (>= 1.15.1)
- Sentry (>= 5.14.1 && < 7.0.0)
- Sentry.Extensions.Logging (>= 5.14.1 && < 7.0.0)
- StackExchange.Utils.Configuration (>= 0.1.12)
- System.Linq.Dynamic.Core (>= 1.7.2)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on NewHeap.Platform.Common:
| Package | Downloads |
|---|---|
|
NewHeap.Platform.Events.Cap
CAP-based transactional event publishing with SQL Server and PostgreSQL integrations for NewHeap Platform applications. |
|
|
NewHeap.Platform.Media.Core
Provider-neutral media contracts, models, composition, and relational file-structure behavior for NewHeap Platform applications. |
|
|
NewHeap.Platform.AspNet.Common
ASP.NET Core authentication, authorization, repository, query, background-job, and observability building blocks for NewHeap Platform applications. |
|
|
NewHeap.Platform.Common.Test
Reusable test contexts, fixtures, assertions, and substitute helpers for applications built with NewHeap.Platform.Common. |
GitHub repositories
This package is not used by any popular GitHub repositories.