Table of Contents

Class Error.InvariantViolation

Namespace
Trellis
Assembly
Trellis.Core.dll

Global or multi-field business invariant was violated (e.g. cross-field rule, computed constraint) outside the inbound-validation pipeline.

public sealed record Error.InvariantViolation : Error, IEquatable<Error>, IEquatable<Error.InvariantViolation>
Inheritance
Error.InvariantViolation
Implements
Inherited Members
Extension Methods

Constructors

InvariantViolation(string, ResourceRef?)

Global or multi-field business invariant was violated (e.g. cross-field rule, computed constraint) outside the inbound-validation pipeline.

public InvariantViolation(string Code, ResourceRef? Resource = null)

Parameters

Code string

Stable machine-readable code identifying the violated invariant.

Resource ResourceRef?

Optional resource the invariant was evaluated against.

Properties

Kind

Gets the stable domain slug for this case (e.g. "not-found", "invalid-input"). Suitable for telemetry, observability dimensions, and as the durable identifier that boundary layers translate into transport-specific type identifiers.

public override string Kind { get; }

Property Value

string

Resource

Optional resource the invariant was evaluated against.

public ResourceRef? Resource { get; init; }

Property Value

ResourceRef?

Methods

For(string, ResourceRef, string?)

Convenience factory that builds an Error.InvariantViolation from an explicit resource reference.

public static Error.InvariantViolation For(string code, ResourceRef resource, string? detail = null)

Parameters

code string

Non-blank machine-readable code identifying the violated invariant.

resource ResourceRef

The resource the invariant was evaluated against.

detail string

Optional human-readable detail.

Returns

Error.InvariantViolation

An Error.InvariantViolation carrying the resource.

ForReason(string, string?)

Convenience factory for an invariant violation with no identifiable resource (e.g. a cross-field or workflow rule with no aggregate context). Bundles the optional Detail that the primary constructor cannot set inline.

public static Error.InvariantViolation ForReason(string code, string? detail = null)

Parameters

code string

Non-blank machine-readable code identifying the violated invariant.

detail string

Optional human-readable detail.

Returns

Error.InvariantViolation

A resourceless Error.InvariantViolation.

For<TResource>(string, object?, string?)

Convenience factory that builds an Error.InvariantViolation against the resource type TResource (its CLR name becomes the resource name), mirroring the Error.Conflict factories. code leads because it is the invariant's required identity, with the resource id optional.

public static Error.InvariantViolation For<TResource>(string code, object? id = null, string? detail = null)

Parameters

code string

Non-blank machine-readable code identifying the violated invariant.

id object

Identifier of the instance the invariant was evaluated against; pass null for an aggregate- or type-level invariant, or use ForReason(string, string?).

detail string

Optional human-readable detail.

Returns

Error.InvariantViolation

An Error.InvariantViolation carrying the resource.

Type Parameters

TResource

The resource the invariant was evaluated against.