Class ConstraintBuilder
- Namespace
- Cratis.Chronicle.Events.Constraints
- Assembly
- Cratis.Chronicle.dll
Represents an implementation of IConstraintBuilder.
public class ConstraintBuilder : IConstraintBuilder
- Inheritance
-
ConstraintBuilder
- Implements
- Inherited Members
- Extension Methods
Constructors
ConstraintBuilder(IEventTypes, INamingPolicy, Type?)
Represents an implementation of IConstraintBuilder.
public ConstraintBuilder(IEventTypes eventTypes, INamingPolicy namingPolicy, Type? owner = null)
Parameters
eventTypesIEventTypesEvent types for the builder.
namingPolicyINamingPolicyThe INamingPolicy to use for converting names during serialization.
ownerTypeOptional owner of the constraint.
Methods
AddConstraint(IConstraintDefinition)
Add a constraint to the builder.
public void AddConstraint(IConstraintDefinition constraint)
Parameters
constraintIConstraintDefinitionConstraint to add.
Build()
Build the constraint.
public IImmutableList<IConstraintDefinition> Build()
Returns
- IImmutableList<IConstraintDefinition>
A collection of IConstraintDefinition to use for registering with server.
ClosesStreamOn<TEvent>(Action<IClosesStreamBuilder<TEvent>>?, ConstraintName?)
Declare an event that closes a stream scope, configured inside the callback.
public IConstraintBuilder ClosesStreamOn<TEvent>(Action<IClosesStreamBuilder<TEvent>>? configure = null, ConstraintName? name = null)
Parameters
configureAction<IClosesStreamBuilder<TEvent>>Optional scope and reopening configuration.
nameConstraintNameOptional owner name, defaulting to the event type identifier.
Returns
- IConstraintBuilder
The builder for continuation.
Type Parameters
TEventThe closing event type.
Exceptions
- ClosesStreamConstraintsNotSupported
The implementation does not support closing events.
- PropertyDoesNotExistOnEventType
A closing or reopening type lacks the configured property.
- MissingNameForClosesStreamConstraint
The configured owner name is reserved for manual closures.
ForEventLog()
Apply the constraints only to the event log.
public IConstraintBuilder ForEventLog()
Returns
- IConstraintBuilder
Builder for continuation.
Remarks
Shorthand for ForEventSequences(params EventSequenceId[]) with Log. Uniqueness is usually a rule of the event log, and other sequences such as the outbox carry facts that were already validated there.
ForEventSequences(params EventSequenceId[])
Apply the constraints only to specific event sequences.
public IConstraintBuilder ForEventSequences(params EventSequenceId[] eventSequenceIds)
Parameters
eventSequenceIdsEventSequenceId[]The EventSequenceId values of the event sequences the constraints apply to.
Returns
- IConstraintBuilder
Builder for continuation.
Remarks
By default a constraint applies to every event sequence its event types are appended to, and every sequence keeps an index of its own. The kernel neither validates nor indexes a constraint for an event sequence it does not apply to. That matters when the same event type is forwarded to another sequence, such as the outbox: the forwarded copy would otherwise claim the value in the outbox's own index, which only removal events appended to the outbox could release.
It applies to every constraint defined on this builder, wherever in the chain it is called, and calling it again adds to the event sequences already declared.
PerEventSourceType()
Scope the constraint per event source type.
public IConstraintBuilder PerEventSourceType()
Returns
- IConstraintBuilder
Builder for continuation.
PerEventStreamId()
Scope the constraint per event stream identifier.
public IConstraintBuilder PerEventStreamId()
Returns
- IConstraintBuilder
Builder for continuation.
PerEventStreamType()
Scope the constraint per event stream type.
public IConstraintBuilder PerEventStreamType()
Returns
- IConstraintBuilder
Builder for continuation.
RemovedWith<TRemovalEventType>()
Indicate an event that releases the unique event type constraint most recently declared on this builder.
public IConstraintBuilder RemovedWith<TRemovalEventType>()
Returns
- IConstraintBuilder
Builder for continuation.
Type Parameters
TRemovalEventTypeType of event that releases the constraint.
Remarks
Without this the constraint can only say "at most one, forever". Most lifecycles cycle, so declare the event that ends a cycle and the covered event types are allowed again for the next one — a covered event only violates the constraint when it comes after the most recent removal event on the same event source.
It applies to the Unique<TEventType>(ConstraintViolationMessage?, ConstraintName?) declaration it follows, which is why it belongs on the same chain. Call it as many times as the lifecycle has terminal facts: every declared event type releases the constraint on its own, and declaring a second does not replace the first. Declaring several event types under one constraint name makes them one constraint, which is released by every removal event declared for that name.
Exceptions
- NoUniqueEventTypeConstraintToRemove
Thrown when no unique event type constraint has been declared on the builder yet.
Unique(Action<IUniqueConstraintBuilder>)
Start building a unique constraint.
public IConstraintBuilder Unique(Action<IUniqueConstraintBuilder> callback)
Parameters
callbackAction<IUniqueConstraintBuilder>Callback with IUniqueConstraintBuilder for building.
Returns
- IConstraintBuilder
Builder for continuation.
Unique<TEventType>(ConstraintViolationMessage?, ConstraintName?)
Adds a unique constraint for a specific event type. This means there can only be one instance of this event type per event source identifier.
public IConstraintBuilder Unique<TEventType>(ConstraintViolationMessage? message = null, ConstraintName? name = null)
Parameters
messageConstraintViolationMessageOptional message for the constraint.
nameConstraintNameOptional name for the constraint.
Returns
- IConstraintBuilder
Builder for continuation.
Type Parameters
TEventTypeType of event to add for.
Unique<TEventType>(ConstraintViolationMessageProvider, ConstraintName?)
Adds a unique constraint for a specific event type. This means there can only be one instance of this event type per event source identifier.
public IConstraintBuilder Unique<TEventType>(ConstraintViolationMessageProvider messageCallback, ConstraintName? name = null)
Parameters
messageCallbackConstraintViolationMessageProviderCallback for providing message for the constraint.
nameConstraintNameOptional name for the constraint.
Returns
- IConstraintBuilder
Builder for continuation.
Type Parameters
TEventTypeType of event to add for.