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
CodestringStable machine-readable code identifying the violated invariant.
ResourceResourceRef?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
Resource
Optional resource the invariant was evaluated against.
public ResourceRef? Resource { get; init; }
Property Value
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
codestringNon-blank machine-readable code identifying the violated invariant.
resourceResourceRefThe resource the invariant was evaluated against.
detailstringOptional 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
codestringNon-blank machine-readable code identifying the violated invariant.
detailstringOptional 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
codestringNon-blank machine-readable code identifying the violated invariant.
idobjectIdentifier of the instance the invariant was evaluated against; pass null for an aggregate- or type-level invariant, or use ForReason(string, string?).
detailstringOptional human-readable detail.
Returns
- Error.InvariantViolation
An Error.InvariantViolation carrying the resource.
Type Parameters
TResourceThe resource the invariant was evaluated against.