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
nameConstraintNameName of the constraint.
messageCallbackConstraintViolationMessageProviderThe callback that provides the ConstraintViolationMessage of the constraint.
eventTypeIdsIEnumerable<EventTypeId>The EventTypeId values the constraint covers.
removedWithEventTypeIdThe EventTypeId of the event that removes the constraint, or null for none.
scopeConstraintScopeThe 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
NameConstraintNameName of the constraint.
MessageCallbackConstraintViolationMessageProviderthe callback that provides the ConstraintViolationMessage of the constraint.
EventTypeIdsIEnumerable<EventTypeId>The EventTypeId values the constraint covers.
RemovedWithIEnumerable<EventTypeId>The EventTypeId values of the events that remove the constraint.
ScopeConstraintScopeThe 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
originalUniqueEventTypeConstraintDefinition
Properties
EqualityContract
protected virtual Type EqualityContract { get; }
Property Value
EventSequences
Gets the EventSequenceId values of the event sequences the constraint applies to.
public IEnumerable<EventSequenceId> EventSequences { get; init; }
Property Value
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
MessageCallback
the callback that provides the ConstraintViolationMessage of the constraint.
public ConstraintViolationMessageProvider MessageCallback { get; init; }
Property Value
Name
Name of the constraint.
public ConstraintName Name { get; init; }
Property Value
RemovedWith
The EventTypeId values of the events that remove the constraint.
public IEnumerable<EventTypeId> RemovedWith { get; init; }
Property Value
Scope
The ConstraintScope for the constraint.
public ConstraintScope? Scope { get; init; }
Property Value
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
NameConstraintNameMessageCallbackConstraintViolationMessageProviderEventTypeIdsIEnumerable<EventTypeId>RemovedWithIEnumerable<EventTypeId>ScopeConstraintScope
Equals(UniqueEventTypeConstraintDefinition?)
public virtual bool Equals(UniqueEventTypeConstraintDefinition? other)
Parameters
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
objobject
Returns
GetHashCode()
public override int GetHashCode()
Returns
PrintMembers(StringBuilder)
protected virtual bool PrintMembers(StringBuilder builder)
Parameters
builderStringBuilder
Returns
ToString()
public override string ToString()
Returns
Operators
operator ==(UniqueEventTypeConstraintDefinition?, UniqueEventTypeConstraintDefinition?)
public static bool operator ==(UniqueEventTypeConstraintDefinition? left, UniqueEventTypeConstraintDefinition? right)
Parameters
Returns
operator !=(UniqueEventTypeConstraintDefinition?, UniqueEventTypeConstraintDefinition?)
public static bool operator !=(UniqueEventTypeConstraintDefinition? left, UniqueEventTypeConstraintDefinition? right)