Class EventContext

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

Represents the context in which an event exists in - typically what it was appended with.

public record EventContext : IEquatable<EventContext>
Inheritance
EventContext
Implements
Inherited Members
Extension Methods

Constructors

EventContext(EventContext)

protected EventContext(EventContext original)

Parameters

original EventContext

EventContext(EventType, EventSourceType, EventSourceId, EventStreamType, EventStreamId, EventSequenceNumber, DateTimeOffset, EventStoreName, EventStoreNamespaceName, CorrelationId, IEnumerable<Causation>, Identity, IEnumerable<Tag>, EventHash, EventObservationState, Subject)

Represents the context in which an event exists in - typically what it was appended with.

public EventContext(EventType EventType, EventSourceType EventSourceType, EventSourceId EventSourceId, EventStreamType EventStreamType, EventStreamId EventStreamId, EventSequenceNumber SequenceNumber, DateTimeOffset Occurred, EventStoreName EventStore, EventStoreNamespaceName Namespace, CorrelationId CorrelationId, IEnumerable<Causation> Causation, Identity CausedBy, IEnumerable<Tag> Tags, EventHash Hash, EventObservationState ObservationState = EventObservationState.Initial, Subject Subject = null)

Parameters

EventType EventType

The EventType of the event.

EventSourceType EventSourceType

The EventSourceType.

EventSourceId EventSourceId

The EventSourceId.

EventStreamType EventStreamType

The EventStreamType.

EventStreamId EventStreamId

The EventStreamId.

SequenceNumber EventSequenceNumber

The EventSequenceNumber of the event as persisted in the event sequence.

Occurred DateTimeOffset

When it occurred.

EventStore EventStoreName

The EventStoreName the event belongs to.

Namespace EventStoreNamespaceName

The EventStoreNamespaceName the event belongs to.

CorrelationId CorrelationId

The CorrelationId for the event.

Causation IEnumerable<Causation>

A collection of Causation for what caused the event.

CausedBy Identity

A collection of Identities that caused the event.

Tags IEnumerable<Tag>

The tags associated with the event.

Hash EventHash

The EventHash of the event content.

ObservationState EventObservationState

Holds the state relevant for the observer observing.

Subject Subject

The Subject identifying the compliance target for this event. Always set — defaults to the EventSourceId value when no explicit subject is provided.

Fields

Empty

Creates an 'empty' EventContext with the event source id set to empty and all properties default.

public static readonly EventContext Empty

Field Value

EventContext

A new EventContext.

Properties

AppendedGeneration

Gets the generation the event was appended in, or null when unknown.

public EventTypeGeneration? AppendedGeneration { get; init; }

Property Value

EventTypeGeneration

Causation

A collection of Causation for what caused the event.

public IEnumerable<Causation> Causation { get; init; }

Property Value

IEnumerable<Causation>

CausedBy

A collection of Identities that caused the event.

public Identity CausedBy { get; init; }

Property Value

Identity

CorrelationId

The CorrelationId for the event.

public CorrelationId CorrelationId { get; init; }

Property Value

CorrelationId

EqualityContract

protected virtual Type EqualityContract { get; }

Property Value

Type

EventSource

Gets the name of the registered event source definition the event was appended through. NotSet when it was not appended through a definition, including events stored before event sources existed.

public EventSourceName EventSource { get; init; }

Property Value

EventSourceName

Remarks

Declared outside the primary constructor so existing positional construction and deconstruction shapes remain compatible.

EventSourceId

public EventSourceId EventSourceId { get; init; }

Property Value

EventSourceId

EventSourceType

public EventSourceType EventSourceType { get; init; }

Property Value

EventSourceType

EventStore

The EventStoreName the event belongs to.

public EventStoreName EventStore { get; init; }

Property Value

EventStoreName

EventStreamId

public EventStreamId EventStreamId { get; init; }

Property Value

EventStreamId

EventStreamType

public EventStreamType EventStreamType { get; init; }

Property Value

EventStreamType

EventType

The EventType of the event.

public EventType EventType { get; init; }

Property Value

EventType

Hash

The EventHash of the event content.

public EventHash Hash { get; init; }

Property Value

EventHash

NamedTags

Gets the structured named tags associated with the event.

public IEnumerable<NamedTag> NamedTags { get; init; }

Property Value

IEnumerable<NamedTag>

Exceptions

InvalidNamedTag

The supplied collection contains a null named tag.

Namespace

The EventStoreNamespaceName the event belongs to.

public EventStoreNamespaceName Namespace { get; init; }

Property Value

EventStoreNamespaceName

ObservationState

Holds the state relevant for the observer observing.

public EventObservationState ObservationState { get; init; }

Property Value

EventObservationState

Occurred

When it occurred.

public DateTimeOffset Occurred { get; init; }

Property Value

DateTimeOffset

SequenceNumber

The EventSequenceNumber of the event as persisted in the event sequence.

public EventSequenceNumber SequenceNumber { get; init; }

Property Value

EventSequenceNumber

Subject

The Subject identifying the compliance target for this event. Always set — defaults to the EventSourceId value when no explicit subject is provided.

public Subject Subject { get; init; }

Property Value

Subject

SubjectIsEventSourceId

Gets a value indicating whether the subject is the event source id (no explicit Subject was set, or Subject equals EventSourceId).

public bool SubjectIsEventSourceId { get; }

Property Value

bool

Tags

The tags associated with the event.

public IEnumerable<Tag> Tags { get; init; }

Property Value

IEnumerable<Tag>

Methods

Deconstruct(out EventType, out EventSourceType, out EventSourceId, out EventStreamType, out EventStreamId, out EventSequenceNumber, out DateTimeOffset, out EventStoreName, out EventStoreNamespaceName, out CorrelationId, out IEnumerable<Causation>, out Identity, out IEnumerable<Tag>, out EventHash, out EventObservationState, out Subject)

public void Deconstruct(out EventType EventType, out EventSourceType EventSourceType, out EventSourceId EventSourceId, out EventStreamType EventStreamType, out EventStreamId EventStreamId, out EventSequenceNumber SequenceNumber, out DateTimeOffset Occurred, out EventStoreName EventStore, out EventStoreNamespaceName Namespace, out CorrelationId CorrelationId, out IEnumerable<Causation> Causation, out Identity CausedBy, out IEnumerable<Tag> Tags, out EventHash Hash, out EventObservationState ObservationState, out Subject Subject)

Parameters

EventType EventType
EventSourceType EventSourceType
EventSourceId EventSourceId
EventStreamType EventStreamType
EventStreamId EventStreamId
SequenceNumber EventSequenceNumber
Occurred DateTimeOffset
EventStore EventStoreName
Namespace EventStoreNamespaceName
CorrelationId CorrelationId
Causation IEnumerable<Causation>
CausedBy Identity
Tags IEnumerable<Tag>
Hash EventHash
ObservationState EventObservationState
Subject Subject

EmptyWithEventSourceId(EventSourceId)

Creates an empty EventContext for a specific EventSourceId.

public static EventContext EmptyWithEventSourceId(EventSourceId eventSourceId)

Parameters

eventSourceId EventSourceId

EventSourceId to create for.

Returns

EventContext

A new EventContext.

Equals(EventContext?)

public virtual bool Equals(EventContext? other)

Parameters

other EventContext

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

From(EventStoreName, EventStoreNamespaceName, EventType, EventSourceType, EventSourceId, EventStreamType, EventStreamId, EventSequenceNumber, CorrelationId, DateTimeOffset?)

Creates a new EventContext from EventSourceId and other optional parameters.

public static EventContext From(EventStoreName eventStore, EventStoreNamespaceName @namespace, EventType eventType, EventSourceType eventSourceType, EventSourceId eventSourceId, EventStreamType eventStreamType, EventStreamId eventStreamId, EventSequenceNumber sequenceNumber, CorrelationId correlationId, DateTimeOffset? occurred = null)

Parameters

eventStore EventStoreName

EventStoreName the context is for.

namespace EventStoreNamespaceName

EventStoreNamespaceName the context is for.

eventType EventType

EventType to create from.

eventSourceType EventSourceType

EventSourceType to create from.

eventSourceId EventSourceId

EventSourceId to create from.

eventStreamType EventStreamType

EventStreamType to create from.

eventStreamId EventStreamId

EventStreamId to create from.

sequenceNumber EventSequenceNumber

The EventSequenceNumber of the event as persisted in the event sequence.

correlationId CorrelationId

The CorrelationId for the event.

occurred DateTimeOffset?

Optional occurrence time. Defaults to UtcNow when omitted.

Returns

EventContext

A new EventContext.

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

WithState(EventObservationState)

Creates a copy of the context object with the new desired state.

public EventContext WithState(EventObservationState desiredState)

Parameters

desiredState EventObservationState

The desired state.

Returns

EventContext

A new copy with the desired state set.

Operators

operator ==(EventContext?, EventContext?)

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

Parameters

left EventContext
right EventContext

Returns

bool

operator !=(EventContext?, EventContext?)

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

Parameters

left EventContext
right EventContext

Returns

bool