Class UniqueEventTypeConstraintDefinition

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

Represents a definition of a unique event type constraint.

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

Remarks

The constraint allows at most one event drawn from the covered event types per event source. Declare several event types under one constraint name to make them mutually exclusive — an event source that is terminal through either of two outcomes can then have one of them, never both and never twice.

More than one event type can release the constraint, because a cycle can end in more than one way. Each one releases it on its own, so the next cycle is allowed after whichever of them was appended most recently.

Constructors

UniqueEventTypeConstraintDefinition(ConstraintName, ConstraintViolationMessageProvider, IEnumerable<EventTypeId>, EventTypeId?, ConstraintScope?)

Initializes a new instance of the UniqueEventTypeConstraintDefinition 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 UniqueEventTypeConstraintDefinition(ConstraintName name, ConstraintViolationMessageProvider messageCallback, IEnumerable<EventTypeId> eventTypeIds, EventTypeId? removedWith, ConstraintScope? scope)

Parameters

name ConstraintName

Name of the constraint.

messageCallback ConstraintViolationMessageProvider

The callback that provides the ConstraintViolationMessage of the constraint.

eventTypeIds IEnumerable<EventTypeId>

The EventTypeId values the constraint covers.

removedWith EventTypeId

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

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.

UniqueEventTypeConstraintDefinition(ConstraintName, ConstraintViolationMessageProvider, IEnumerable<EventTypeId>, IEnumerable<EventTypeId>, ConstraintScope?)

Represents a definition of a unique event type constraint.

public UniqueEventTypeConstraintDefinition(ConstraintName Name, ConstraintViolationMessageProvider MessageCallback, IEnumerable<EventTypeId> EventTypeIds, IEnumerable<EventTypeId> RemovedWith, ConstraintScope? Scope = null)

Parameters

Name ConstraintName

Name of the constraint.

MessageCallback ConstraintViolationMessageProvider

the callback that provides the ConstraintViolationMessage of the constraint.

EventTypeIds IEnumerable<EventTypeId>

The EventTypeId values the constraint covers.

RemovedWith IEnumerable<EventTypeId>

The EventTypeId values of the events that remove the constraint.

Scope ConstraintScope

The ConstraintScope for the constraint.

Remarks

The constraint allows at most one event drawn from the covered event types per event source. Declare several event types under one constraint name to make them mutually exclusive — an event source that is terminal through either of two outcomes can then have one of them, never both and never twice.

More than one event type can release the constraint, because a cycle can end in more than one way. Each one releases it on its own, so the next cycle is allowed after whichever of them was appended most recently.

UniqueEventTypeConstraintDefinition(UniqueEventTypeConstraintDefinition)

protected UniqueEventTypeConstraintDefinition(UniqueEventTypeConstraintDefinition original)

Parameters

original UniqueEventTypeConstraintDefinition

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.

EventTypeIds

The EventTypeId values the constraint covers.

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

Property Value

IEnumerable<EventTypeId>

MessageCallback

the callback that provides the ConstraintViolationMessage of the constraint.

public ConstraintViolationMessageProvider MessageCallback { get; init; }

Property Value

ConstraintViolationMessageProvider

Name

Name of the constraint.

public ConstraintName Name { get; init; }

Property Value

ConstraintName

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<EventTypeId>, out IEnumerable<EventTypeId>, out ConstraintScope?)

public void Deconstruct(out ConstraintName Name, out ConstraintViolationMessageProvider MessageCallback, out IEnumerable<EventTypeId> EventTypeIds, out IEnumerable<EventTypeId> RemovedWith, out ConstraintScope? Scope)

Parameters

Name ConstraintName
MessageCallback ConstraintViolationMessageProvider
EventTypeIds IEnumerable<EventTypeId>
RemovedWith IEnumerable<EventTypeId>
Scope ConstraintScope

Equals(UniqueEventTypeConstraintDefinition?)

public virtual bool Equals(UniqueEventTypeConstraintDefinition? other)

Parameters

other UniqueEventTypeConstraintDefinition

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 ==(UniqueEventTypeConstraintDefinition?, UniqueEventTypeConstraintDefinition?)

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

Parameters

left UniqueEventTypeConstraintDefinition
right UniqueEventTypeConstraintDefinition

Returns

bool

operator !=(UniqueEventTypeConstraintDefinition?, UniqueEventTypeConstraintDefinition?)

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

Parameters

left UniqueEventTypeConstraintDefinition
right UniqueEventTypeConstraintDefinition

Returns

bool