Table of Contents

Class ContentHash

Namespace
Integrations.Application.Common
Assembly
Integrations.Application.dll

Content hashes for idempotency: "is this replay the same request as the one already stored?".

The hash covers a canonical form of the request, not its raw JSON: null members are dropped, object keys are sorted and decimals are normalized (100.00 and 100 are the same amount). So adding an optional (nullable) member to a contract does not change the hash of requests that leave it out, and a replay of a stored document stays a replay after a deploy. Hashes carry a version prefix (Version) so the canonical form can change again without confusing old rows.

public static class ContentHash
Inheritance
ContentHash
Inherited Members

Fields

Version

Prefix of hashes produced by Of<T>(T).

public const string Version = "v1"

Field Value

string

Methods

Matches<T>(string?, T)

Whether stored is the hash of value, either canonical or the pre-v1 form (SHA-256 of the raw JSON) that rows created before the canonical hash still carry.

public static bool Matches<T>(string? stored, T value)

Parameters

stored string

Hash stored on the row.

value T

The incoming request, in the same shape that was hashed when the row was stored.

Returns

bool

True when the request is a replay of the stored one.

Type Parameters

T

Request type.

Of<T>(T)

Canonical content hash of value: v1: followed by 64 hex characters.

public static string Of<T>(T value)

Parameters

value T

The request (or an anonymous object combining it with path values).

Returns

string

The versioned hash.

Type Parameters

T

Request type.