Class UniqueConstraintDefinition

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

Represents a definition of a unique event type constraint.

public record UniqueConstraintDefinition : IConstraintDefinition, IEquatable<UniqueConstraintDefinition>
Inheritance
UniqueConstraintDefinition
Implements
Inherited Members
Extension Methods

Remarks

A lifecycle can end in more than one way, so more than one event type can release the claimed value. Each one releases it on its own — the first of them appended for an event source frees the value for anyone to claim.

Constructors

UniqueConstraintDefinition(ConstraintName, ConstraintViolationMessageProvider, IEnumerable<UniqueConstraintEventDefinition>, EventTypeId?, bool, ConstraintScope?)

Initializes a new instance of the UniqueConstraintDefinition class from a single removal event.

[Obsolete("A constraint can be released by more than one event. Pass a collection of event type ids instead - this overload wraps the single value and will be removed.")]
public UniqueConstraintDefinition(ConstraintName name, ConstraintViolationMessageProvider messageCallback, IEnumerable<UniqueConstraintEventDefinition> eventsWithProperties, EventTypeId? removedWith, bool ignoreCasing, ConstraintScope? scope)

Parameters

name ConstraintName

Name of the constraint.

messageCallback ConstraintViolationMessageProvider

The callback that provides the ConstraintViolationMessage of the constraint.

eventsWithProperties IEnumerable<UniqueConstraintEventDefinition>

The EventType and properties the constraint is for.

removedWith EventTypeId

The EventTypeId of the event that removes the constraint, or null for none.

ignoreCasing bool

Whether this constraint should ignore casing.

scope ConstraintScope

The ConstraintScope for the constraint.

Remarks

The signature this type had while a constraint could only be released by one event. It is kept so that an assembly compiled against that shape keeps linking: optional arguments are baked in at the call site, so every previously compiled call refers to the full argument list, which is what this restores.

UniqueConstraintDefinition(ConstraintName, ConstraintViolationMessageProvider, IEnumerable<UniqueConstraintEventDefinition>, IEnumerable<EventTypeId>, bool, ConstraintScope?)

Represents a definition of a unique event type constraint.

public UniqueConstraintDefinition(ConstraintName Name, ConstraintViolationMessageProvider MessageCallback, IEnumerable<UniqueConstraintEventDefinition> EventsWithProperties, IEnumerable<EventTypeId> RemovedWith, bool IgnoreCasing, ConstraintScope? Scope = null)

Parameters

Name ConstraintName

Name of the constraint.

MessageCallback ConstraintViolationMessageProvider

the callback that provides the ConstraintViolationMessage of the constraint.

EventsWithProperties IEnumerable<UniqueConstraintEventDefinition>

The EventType and properties the constraint is for.

RemovedWith IEnumerable<EventTypeId>

The EventTypeId values of the events that remove the constraint.

IgnoreCasing bool

Whether this constraint should ignore casing.

Scope ConstraintScope

The ConstraintScope for the constraint.

Remarks

A lifecycle can end in more than one way, so more than one event type can release the claimed value. Each one releases it on its own — the first of them appended for an event source frees the value for anyone to claim.

UniqueConstraintDefinition(UniqueConstraintDefinition)

protected UniqueConstraintDefinition(UniqueConstraintDefinition original)

Parameters

original UniqueConstraintDefinition

Properties

EqualityContract

protected virtual Type EqualityContract { get; }

Property Value

Type

EventSequences

Gets the EventSequenceId values of the event sequences the constraint applies to.

public IEnumerable<EventSequenceId> EventSequences { get; init; }

Property Value

IEnumerable<EventSequenceId>

Remarks

Empty means every event sequence, which is the default. The constraint is not validated - and claims nothing - for an event sequence it does not apply to.

EventsWithProperties

The EventType and properties the constraint is for.

public IEnumerable<UniqueConstraintEventDefinition> EventsWithProperties { get; init; }

Property Value

IEnumerable<UniqueConstraintEventDefinition>

IgnoreCasing

Whether this constraint should ignore casing.

public bool IgnoreCasing { get; init; }

Property Value

bool

MessageCallback

the callback that provides the ConstraintViolationMessage of the constraint.

public ConstraintViolationMessageProvider MessageCallback { get; init; }

Property Value

ConstraintViolationMessageProvider

Mode

Gets how claimed values are retained.

public UniqueConstraintMode Mode { get; init; }

Property Value

UniqueConstraintMode

Name

Name of the constraint.

public ConstraintName Name { get; init; }

Property Value

ConstraintName

RemovalEventDefinitions

Gets the removal events and properties identifying the value to release.

public IEnumerable<UniqueConstraintEventDefinition> RemovalEventDefinitions { get; init; }

Property Value

IEnumerable<UniqueConstraintEventDefinition>

RemovedWith

The EventTypeId values of the events that remove the constraint.

public IEnumerable<EventTypeId> RemovedWith { get; init; }

Property Value

IEnumerable<EventTypeId>

Scope

The ConstraintScope for the constraint.

public ConstraintScope? Scope { get; init; }

Property Value

ConstraintScope

Methods

Deconstruct(out ConstraintName, out ConstraintViolationMessageProvider, out IEnumerable<UniqueConstraintEventDefinition>, out IEnumerable<EventTypeId>, out bool, out ConstraintScope?)

public void Deconstruct(out ConstraintName Name, out ConstraintViolationMessageProvider MessageCallback, out IEnumerable<UniqueConstraintEventDefinition> EventsWithProperties, out IEnumerable<EventTypeId> RemovedWith, out bool IgnoreCasing, out ConstraintScope? Scope)

Parameters

Name ConstraintName
MessageCallback ConstraintViolationMessageProvider
EventsWithProperties IEnumerable<UniqueConstraintEventDefinition>
RemovedWith IEnumerable<EventTypeId>
IgnoreCasing bool
Scope ConstraintScope

Equals(UniqueConstraintDefinition?)

public virtual bool Equals(UniqueConstraintDefinition? other)

Parameters

other UniqueConstraintDefinition

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

PrintMembers(StringBuilder)

protected virtual bool PrintMembers(StringBuilder builder)

Parameters

builder StringBuilder

Returns

bool

ToString()

public override string ToString()

Returns

string

Operators

operator ==(UniqueConstraintDefinition?, UniqueConstraintDefinition?)

public static bool operator ==(UniqueConstraintDefinition? left, UniqueConstraintDefinition? right)

Parameters

left UniqueConstraintDefinition
right UniqueConstraintDefinition

Returns

bool

operator !=(UniqueConstraintDefinition?, UniqueConstraintDefinition?)

public static bool operator !=(UniqueConstraintDefinition? left, UniqueConstraintDefinition? right)

Parameters

left UniqueConstraintDefinition
right UniqueConstraintDefinition

Returns

bool