Class Projections

Namespace
Cratis.Chronicle.Projections
Assembly
Cratis.Chronicle.dll

Represents an implementation of IProjections.

public class Projections : IProjections
Inheritance
Projections
Implements
Inherited Members
Extension Methods

Remarks

Initializes a new instance of the Projections class.

Constructors

Projections(IEventStore, IEventTypes, IClientArtifactsProvider, INamingPolicy, IClientArtifactsActivator, JsonSerializerOptions, ILogger<Projections>)

Represents an implementation of IProjections.

public Projections(IEventStore eventStore, IEventTypes eventTypes, IClientArtifactsProvider clientArtifacts, INamingPolicy namingPolicy, IClientArtifactsActivator artifactsActivator, JsonSerializerOptions jsonSerializerOptions, ILogger<Projections> logger)

Parameters

eventStore IEventStore

IEventStore the projections belongs to.

eventTypes IEventTypes

All the IEventTypes.

clientArtifacts IClientArtifactsProvider

Optional IClientArtifactsProvider for the client artifacts.

namingPolicy INamingPolicy

The INamingPolicy to use for converting names during serialization.

artifactsActivator IClientArtifactsActivator

IClientArtifactsActivator for activating instances of projections.

jsonSerializerOptions JsonSerializerOptions

The JsonSerializerOptions to use for any JSON serialization.

logger ILogger<Projections>

ILogger<TCategoryName> for logging.

Remarks

Initializes a new instance of the Projections class.

Methods

Discover()

Discover all projections from entry assembly and dependencies.

public Task Discover()

Returns

Task

Awaitable task.

FastForward(ProjectionId)

Fast forward a specific projection by its identifier to the tail of the event log, skipping every event it has not yet handled without invoking it.

public Task<FastForwardResult> FastForward(ProjectionId projectionId)

Parameters

projectionId ProjectionId

ProjectionId to fast forward.

Returns

Task<FastForwardResult>

The FastForwardResult describing what happened.

FastForward<TProjection>()

Fast forward a projection to the tail of the event log, skipping every event it has not yet handled without invoking it.

public Task<FastForwardResult> FastForward<TProjection>() where TProjection : IProjection

Returns

Task<FastForwardResult>

The FastForwardResult describing what happened.

Type Parameters

TProjection

Type of projection to fast forward.

GetAllHandlers()

Get all registered handlers.

public IEnumerable<IProjectionHandler> GetAllHandlers()

Returns

IEnumerable<IProjectionHandler>

Collection of IProjectionHandler.

GetExternalEventStoreSubscriptions()

Get the external event store subscription requirements derived from all discovered projection definitions.

public IEnumerable<(string EventStoreName, IEnumerable<EventTypeId> EventTypeIds)> GetExternalEventStoreSubscriptions()

Returns

IEnumerable<(string EventStoreName, IEnumerable<EventTypeId> EventTypeIds)>

A collection of tuples mapping external event store names to their event type identifiers.

Remarks

Returns one entry per external event store name, collecting all event type identifiers used by projections whose event sequence is an inbox sequence for that store.

GetFailedPartitionsFor(Type)

Get any failed partitions for a specific projection.

public Task<IEnumerable<FailedPartition>> GetFailedPartitionsFor(Type projectionType)

Parameters

projectionType Type

Type of projection, or the type of read model it projects to.

Returns

Task<IEnumerable<FailedPartition>>

Collection of FailedPartition, if any.

Remarks

This one accepts either handle. It only ever resolved read model types, so narrowing it to what its parameter name says would break every caller it has - and model-bound projections, which have no projection type at all, would lose their only handle. Prefer GetFailedPartitionsForModel(Type) or GetFailedPartitionsFor<TProjection>(), which each say which handle they take.

GetFailedPartitionsForModel(Type)

Get any failed partitions for the projection that maintains a specific read model.

public Task<IEnumerable<FailedPartition>> GetFailedPartitionsForModel(Type readModelType)

Parameters

readModelType Type

Type of read model to get for.

Returns

Task<IEnumerable<FailedPartition>>

Collection of FailedPartition, if any.

GetFailedPartitionsForModel<TReadModel>()

Get any failed partitions for the projection that maintains a specific read model.

public Task<IEnumerable<FailedPartition>> GetFailedPartitionsForModel<TReadModel>()

Returns

Task<IEnumerable<FailedPartition>>

Collection of FailedPartition, if any.

Type Parameters

TReadModel

Type of read model to get for.

GetFailedPartitionsFor<TProjection>()

Get any failed partitions for a specific projection.

public Task<IEnumerable<FailedPartition>> GetFailedPartitionsFor<TProjection>() where TProjection : IProjection

Returns

Task<IEnumerable<FailedPartition>>

Collection of FailedPartition, if any.

Type Parameters

TProjection

Type of projection.

GetHandlerFor<TProjection>()

Get the IProjectionHandler for a specific projection type.

public IProjectionHandler GetHandlerFor<TProjection>() where TProjection : IProjection

Returns

IProjectionHandler

IProjectionHandler for the projection.

Type Parameters

TProjection

Type of projection to get for.

GetProjectionIdForModel(Type)

Get the ProjectionId for a specific type.

public ProjectionId GetProjectionIdForModel(Type readModelType)

Parameters

readModelType Type

Type of read model to get for.

Returns

ProjectionId

The ProjectionId for the type.

GetProjectionIdForModel<TReadModel>()

Get the ProjectionId for a specific type.

public ProjectionId GetProjectionIdForModel<TReadModel>()

Returns

ProjectionId

The ProjectionId for the type.

Type Parameters

TReadModel

Type of read model to get for.

GetProjectionIdFor<TProjection>()

Get the ProjectionId for a specific type.

public ProjectionId GetProjectionIdFor<TProjection>() where TProjection : IProjection

Returns

ProjectionId

The ProjectionId for the type.

Type Parameters

TProjection

Type of projection to get for.

GetStateForModel(Type)

Get the state of the projection that maintains a specific read model.

public Task<ProjectionState> GetStateForModel(Type readModelType)

Parameters

readModelType Type

Type of read model to get for.

Returns

Task<ProjectionState>

ProjectionState.

GetStateForModel<TReadModel>()

Get the state of the projection that maintains a specific read model.

public Task<ProjectionState> GetStateForModel<TReadModel>()

Returns

Task<ProjectionState>

ProjectionState.

Type Parameters

TReadModel

Type of read model to get for.

Remarks

Model-bound projections are declared on the read model and have no type of their own, so this is the only way to ask for their state. Fluent projections answer to it as well, by the model they project to.

GetStateFor<TProjection>()

Get the state of a specific projection.

public Task<ProjectionState> GetStateFor<TProjection>() where TProjection : IProjection

Returns

Task<ProjectionState>

ProjectionState.

Type Parameters

TProjection

Type of projection get for.

Remarks

A model-bound projection has no projection type to name here - use GetStateForModel<TReadModel>() for those.

HasFor(ProjectionId)

Check if there is a definition for a specific projection identifier.

public bool HasFor(ProjectionId projectionId)

Parameters

projectionId ProjectionId

Identifier of projection.

Returns

bool

True if it exists, false if not.

HasFor(Type)

Check if there is a definition for a specific type.

public bool HasFor(Type readModelType)

Parameters

readModelType Type

Type of read model to check for.

Returns

bool

True if it exists, false if not.

HasFor<TReadModel>()

Check if there is a definition for a specific type.

public bool HasFor<TReadModel>()

Returns

bool

True if it exists, false if not.

Type Parameters

TReadModel

Type of read model to check for.

Query(string, string)

Query a projection declaration against the event log without registering it.

public Task<ProjectionQueryResult> Query(string declaration, string eventSequenceId = "event-log")

Parameters

declaration string

The Projection Declaration Language string to query.

eventSequenceId string

Optional event sequence identifier to query. Defaults to "event-log".

Returns

Task<ProjectionQueryResult>

A ProjectionQueryResult containing the resulting read model entries.

Remarks

The declaration may omit the => ReadModelType target — in that case the read model schema is inferred from the events used in the projection. An inferred read model can never be registered as a permanent projection; query-only declarations are exclusively for ad-hoc exploration.

Exceptions

UnableToQueryProjection

Thrown when the declaration contains errors.

Register()

Register all projections with Chronicle.

public Task Register()

Returns

Task

Awaitable task.

Register<TReadModel>()

Register the model-bound projection declared by the attributes on a read model explicitly, for a read model that is not among the discovered artifacts.

public Task<IProjectionHandler> Register<TReadModel>()

Returns

Task<IProjectionHandler>

The IProjectionHandler for the projection.

Type Parameters

TReadModel

Type of read model carrying the model-bound projection attributes.

Remarks

A read model that discovery already found is not registered twice - its existing handler is returned. The projection is identified by the full name of TReadModel, as a discovered one is, and it is sent to Chronicle and included in later registration passes the same way Register<TReadModel>(Action<IProjectionBuilderFor<TReadModel>>, ProjectionId?) describes.

Exceptions

ReadModelIsNotModelBound

Thrown when TReadModel has no model-bound projection attributes.

ReadModelAlreadyHasProjection

Thrown when a different projection already maintains TReadModel.

VariantReadModelsCannotBeRegisteredExplicitly

Thrown when TReadModel is a variant.

Register<TReadModel>(Action<IProjectionBuilderFor<TReadModel>>, ProjectionId?)

Register a projection for a read model explicitly, defining it through the same builder an IProjectionFor<TReadModel> uses, without the read model or the projection having to be discovered.

public Task<IProjectionHandler> Register<TReadModel>(Action<IProjectionBuilderFor<TReadModel>> define, ProjectionId? id = null)

Parameters

define Action<IProjectionBuilderFor<TReadModel>>

Callback that defines the projection on the IProjectionBuilderFor<TReadModel>.

id ProjectionId

Optional ProjectionId. Defaults to the full name of TReadModel, which is also what a model-bound projection for it would be identified by.

Returns

Task<IProjectionHandler>

The IProjectionHandler for the registered projection.

Type Parameters

TReadModel

Type of read model the projection maintains.

Remarks

The result is an ordinary projection and read model: IReadModels reads it, watches it and resolves it by key exactly as it does a discovered one, and a projection defined with Passive() is computed on demand rather than materialized.

The definition is built immediately, so a mistake in it surfaces here. When the client is connected the read model and projection are sent to Chronicle before this returns. Either way the registration becomes part of every later discovery and registration pass, including the one that runs when the connection is re-established. Registering the same projection identifier for the same read model again replaces its definition.

Exceptions

ReadModelAlreadyHasProjection

Thrown when another projection already maintains TReadModel.

VariantReadModelsCannotBeRegisteredExplicitly

Thrown when the definition declares TReadModel a variant.

Replay(ProjectionId)

Replay a specific projection by its identifier.

public Task<JobId> Replay(ProjectionId projectionId)

Parameters

projectionId ProjectionId

ProjectionId to replay.

Returns

Task<JobId>

The JobId of the replay job that was started or resumed, or NotSet if the projection is not replayable or its observer is not in a state it can replay from (disconnected, quarantined); reconnect or release it before replaying.

Replay<TProjection>()

Replay a specific projection.

public Task<JobId> Replay<TProjection>() where TProjection : IProjection

Returns

Task<JobId>

The JobId of the replay job that was started or resumed, or NotSet if the projection is not replayable or its observer is not in a state it can replay from (disconnected, quarantined); reconnect or release it before replaying.

Type Parameters

TProjection

Type of projection to replay.