Skip to content

projection class

Duncan Jones edited this page Aug 21, 2019 · 3 revisions

Projection Class

The projection class runs a [projection] over the event stream identified by the domain, entity type and _unique identifier- of the entity.

Constructor

public Projection(ProjectionAttribute attribute,
                  string connectionStringName = "")
  • connectionStringName (Optional) The name of the connection string setting to use to connect to the data source that holds the event stream over which to run the projection.

Methods

Process

 public async Task<TProjection> Process<TProjection>(Nullable<DateTime> asOfDate = null) where TProjection : IProjection, new()

This runs the projection over the [events] in the given event stream and returns the resulting projection record.

  • asOfDate (Optional) The date up until which to run the projection. This allows you to return point-in-time values for the projection.

Creating a projection to run

The easiest way to create a new projection to run is to start by creating a class that inherits from the ProjectionBase class. You then add an implementation of the interface IHandleEventType for each type of event that the projection cares about.

    /// <summary>
    /// The running balance of the account
    /// </summary>
    public class Balance
        : ProjectionBase,
        IHandleEventType<MoneyDeposited>,
        IHandleEventType<MoneyWithdrawn >
    {

Then perform whatever operation(s) you need to on receipt of that event type when it is read from the stream:

        public void HandleEventInstance(MoneyDeposited eventInstance)
        {
            if (null != eventInstance )
            {
                currentBalance += eventInstance.AmountDeposited;
            }
        }

When the Process method is called it will run all the events through this in order and return the class when done - from which you can get any state properties.

Clone this wiki locally