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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NewHeap.Platform.Common" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NewHeap.Platform.Common" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NewHeap.Platform.Common" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NewHeap.Platform.Common --version 2.0.0
                    
#r "nuget: NewHeap.Platform.Common, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NewHeap.Platform.Common@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NewHeap.Platform.Common&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NewHeap.Platform.Common&version=2.0.0
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
2.0.0 173 8/20/2026
1.1.4 51 8/20/2026