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
nameConstraintNameName of the constraint.
messageCallbackConstraintViolationMessageProviderThe callback that provides the ConstraintViolationMessage of the constraint.
eventsWithPropertiesIEnumerable<UniqueConstraintEventDefinition>The EventType and properties the constraint is for.
removedWithEventTypeIdThe EventTypeId of the event that removes the constraint, or null for none.
ignoreCasingboolWhether this constraint should ignore casing.
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.
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
NameConstraintNameName of the constraint.
MessageCallbackConstraintViolationMessageProviderthe callback that provides the ConstraintViolationMessage of the constraint.
EventsWithPropertiesIEnumerable<UniqueConstraintEventDefinition>The EventType and properties the constraint is for.
RemovedWithIEnumerable<EventTypeId>The EventTypeId values of the events that remove the constraint.
IgnoreCasingboolWhether this constraint should ignore casing.
ScopeConstraintScopeThe 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
originalUniqueConstraintDefinition
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.
EventsWithProperties
The EventType and properties the constraint is for.
public IEnumerable<UniqueConstraintEventDefinition> EventsWithProperties { get; init; }
Property Value
IgnoreCasing
Whether this constraint should ignore casing.
public bool IgnoreCasing { get; init; }
Property Value
MessageCallback
the callback that provides the ConstraintViolationMessage of the constraint.
public ConstraintViolationMessageProvider MessageCallback { get; init; }
Property Value
Mode
Gets how claimed values are retained.
public UniqueConstraintMode Mode { get; init; }
Property Value
Name
Name of the constraint.
public ConstraintName Name { get; init; }
Property Value
RemovalEventDefinitions
Gets the removal events and properties identifying the value to release.
public IEnumerable<UniqueConstraintEventDefinition> RemovalEventDefinitions { 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<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
NameConstraintNameMessageCallbackConstraintViolationMessageProviderEventsWithPropertiesIEnumerable<UniqueConstraintEventDefinition>RemovedWithIEnumerable<EventTypeId>IgnoreCasingboolScopeConstraintScope
Equals(UniqueConstraintDefinition?)
public virtual bool Equals(UniqueConstraintDefinition? 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 ==(UniqueConstraintDefinition?, UniqueConstraintDefinition?)
public static bool operator ==(UniqueConstraintDefinition? left, UniqueConstraintDefinition? right)
Parameters
Returns
operator !=(UniqueConstraintDefinition?, UniqueConstraintDefinition?)
public static bool operator !=(UniqueConstraintDefinition? left, UniqueConstraintDefinition? right)