Skip to content

eventstream class

Duncan Jones edited this page Oct 31, 2020 · 3 revisions

EventStream class

The EventStream class allows you to append events onto a specific event stream for an entity as uniquely identified by the combination of the domain, the entity type and the unique identifier of the entity.

Constructor

  public EventStream(EventStreamAttribute attribute, 
         string connectionStringName = "",
         IWriteContext context = null)

Properties

  • DomainName (string) - The name of the domain in which the entity that this event stream is found
  • EntityTypeName (string) - The type of the entity for which this event stream is defined
  • InstanceKey (string) - The unique identifier of the instance of that entity

Methods

AppendEvent

public async Task AppendEvent(object eventToAdd,
                              int? expectedTopSequence = null,
                              EventStreamExistenceConstraint streamConstraint = EventStreamExistenceConstraint.Loose)

Appends the given event onto the event stream for the entity.

  • eventToAdd - The instance of the event to append to the end of the event stream
  • expectedTopSequence (Optional) The highest sequence we expect on the event stream. This can be set to prevent an event being written if the actual top of the event stream is higher than the expected top - potentially indicating a data consistency issue.
  • **streamConstraint ** (Optional) A constraint on the existence of the event stream to apply when applying the event.

CreateIfNotExists

public async Task CreateIfNotExists()

Explicitly create the event stream if it does not already exist.
Note that appending an event to an event stream that doesn't yet exist will create a new event stream

Exists

 public async Task<bool> Exists()

Does the event stream identified by the domain/type/instance exist yet?

SetContext

public void SetContext(IWriteContext context)

Set the writer context which is used to "wrap" events written so we know who wrote them (and when and why).

Clone this wiki locally