Class UniqueAttribute

Namespace
Cratis.Chronicle.Events.Constraints
Assembly
Cratis.Chronicle.dll

Attribute to adorn types and properties on event types to indicate uniqueness.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Property, AllowMultiple = false)]
public sealed class UniqueAttribute : Attribute
Inheritance
UniqueAttribute
Inherited Members
Extension Methods

Remarks

Property constraints default to one value per event source, unique across event sources. Claiming a new value releases the previous one. Set Mode to PerValue to retain every value until a removal event releases it; reclaiming a value by the same source is accepted in both modes. Class-level uniqueness remains one event of that type per event source, regardless of this setting.

An attribute argument is a compile-time constant, so a message written here is fixed in one language. A consumer that localizes wants the fluent IConstraint form instead, whose WithMessage(ConstraintViolationMessageProvider) resolves per access and so can follow the current culture.

Constructors

UniqueAttribute(string?, string?)

Attribute to adorn types and properties on event types to indicate uniqueness.

public UniqueAttribute(string? name = null, string? message = null)

Parameters

name string

Optional name of the constraint to use.

message string

Optional message to use when the unique constraint is violated.

Remarks

Property constraints default to one value per event source, unique across event sources. Claiming a new value releases the previous one. Set Mode to PerValue to retain every value until a removal event releases it; reclaiming a value by the same source is accepted in both modes. Class-level uniqueness remains one event of that type per event source, regardless of this setting.

An attribute argument is a compile-time constant, so a message written here is fixed in one language. A consumer that localizes wants the fluent IConstraint form instead, whose WithMessage(ConstraintViolationMessageProvider) resolves per access and so can follow the current culture.

Properties

EventSequences

Gets or sets the identifiers of the event sequences the constraint applies to.

public string[] EventSequences { get; set; }

Property Value

string[]

Remarks

Empty means every event sequence, which is the default. The kernel neither validates nor indexes the constraint for an event sequence it does not apply to - declare the event log alone when the same event type is also forwarded to the outbox: [Unique(EventSequences = [EventSequenceId.LogId])].

When several properties share a constraint name, the event sequences declared on each of them are combined. A property that declares none applies the constraint to every event sequence, and that wins: the combined constraint then applies to every event sequence.

Message

Gets the message to use when the unique constraint is violated.

public string? Message { get; }

Property Value

string

Mode

Gets or sets how a property constraint retains values.

public UniqueConstraintMode Mode { get; set; }

Property Value

UniqueConstraintMode

Name

Gets the name of the constraint.

public string? Name { get; }

Property Value

string