-
Notifications
You must be signed in to change notification settings - Fork 20
projection class
The projection class runs a [projection] over the event stream identified by the domain, entity type and _unique identifier- of the entity.
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.
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.
public async Task<TProjection> Process<TProjection>(TProjection projectionToRun, Nullable<DateTime> asOfDate = null) where TProjection : IProjection
Runs the projection starting from the projection state passed in, over the given event stream and returns the resulting projection record.
-
projectionToRun The starting point of the state to continue applying the projection over.
-
asOfDate (Optional) The date up until which to run the projection. This allows you to return point-in-time values for the projection.
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.