Class ProjectionBuilder<TReadModel, TBuilder>

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

Represents a base projection builder.

public class ProjectionBuilder<TReadModel, TBuilder> : IProjectionBuilder<TReadModel, TBuilder> where TBuilder : class

Type Parameters

TReadModel

Type of read model to build for.

TBuilder

Type of actual builder.

Inheritance
ProjectionBuilder<TReadModel, TBuilder>
Implements
IProjectionBuilder<TReadModel, TBuilder>
Derived
Inherited Members
Extension Methods

Constructors

ProjectionBuilder(INamingPolicy, IEventTypes, JsonSerializerOptions, AutoMap)

Represents a base projection builder.

public ProjectionBuilder(INamingPolicy namingPolicy, IEventTypes eventTypes, JsonSerializerOptions jsonSerializerOptions, AutoMap autoMap)

Parameters

namingPolicy INamingPolicy

The INamingPolicy to use for converting names during serialization.

eventTypes IEventTypes

IEventTypes for providing event type information.

jsonSerializerOptions JsonSerializerOptions

The JsonSerializerOptions to use for any JSON serialization.

autoMap AutoMap

AutoMap behavior for properties - defaults to Enabled at top level.

Fields

_autoMap

protected AutoMap _autoMap

Field Value

AutoMap

_childrenDefinitions

protected readonly Dictionary<PropertyPath, ChildrenDefinition> _childrenDefinitions

Field Value

Dictionary<PropertyPath, ChildrenDefinition>

_fromDefinitions

protected readonly Dictionary<EventType, FromDefinition> _fromDefinitions

Field Value

Dictionary<EventType, FromDefinition>

_fromDerivativesDefinitions

Holds grouped registrations already expanded into _fromDefinitions. Do not also emit these through FromEvery.

protected readonly List<FromDerivativesDefinition> _fromDerivativesDefinitions

Field Value

List<FromDerivativesDefinition>

_fromEveryDefinition

protected FromEveryDefinition _fromEveryDefinition

Field Value

FromEveryDefinition

_initialValues

protected JsonObject _initialValues

Field Value

JsonObject

_joinDefinitions

protected readonly Dictionary<EventType, JoinDefinition> _joinDefinitions

Field Value

Dictionary<EventType, JoinDefinition>

_nestedDefinitions

protected readonly Dictionary<PropertyPath, ChildrenDefinition> _nestedDefinitions

Field Value

Dictionary<PropertyPath, ChildrenDefinition>

_noAutoMapProperties

protected readonly IReadOnlyList<string> _noAutoMapProperties

Field Value

IReadOnlyList<string>

_observedEventStores

protected readonly List<string> _observedEventStores

Field Value

List<string>

_readModelIdentifier

protected ReadModelIdentifier _readModelIdentifier

Field Value

ReadModelIdentifier

_removedWithDefinitions

protected readonly Dictionary<EventType, RemovedWithDefinition> _removedWithDefinitions

Field Value

Dictionary<EventType, RemovedWithDefinition>

_removedWithJoinDefinitions

protected readonly Dictionary<EventType, RemovedWithJoinDefinition> _removedWithJoinDefinitions

Field Value

Dictionary<EventType, RemovedWithJoinDefinition>

Methods

AutoMap()

Automatically map event properties to model properties on the events added.

public IProjectionBuilder<TReadModel, TBuilder> AutoMap()

Returns

IProjectionBuilder<TReadModel, TBuilder>

Builder continuation.

Remarks

AutoMap is enabled by default. This method is for explicitly enabling it if needed.

BuildDefinitions(EventGenerationDelivery)

Expands clauses after passive and wildcard declarations have determined the root's effective policy.

protected void BuildDefinitions(EventGenerationDelivery generationDelivery)

Parameters

generationDelivery EventGenerationDelivery

The root projection's effective generation delivery policy.

Exceptions

TypeIsNotAnEventType

A clause's type is not an event type under the effective policy.

Children<TChildModel>(Expression<Func<TReadModel, IEnumerable<TChildModel>>>, Action<IChildrenBuilder<TReadModel, TChildModel>>)

Start building the children projection for a specific child model.

public TBuilder Children<TChildModel>(Expression<Func<TReadModel, IEnumerable<TChildModel>>> targetProperty, Action<IChildrenBuilder<TReadModel, TChildModel>> builderCallback)

Parameters

targetProperty Expression<Func<TReadModel, IEnumerable<TChildModel>>>

Expression for expressing the target property.

builderCallback Action<IChildrenBuilder<TReadModel, TChildModel>>

Builder callback.

Returns

TBuilder

Builder continuation.

Type Parameters

TChildModel

Type of nested child model.

CollectEventStore(Type)

Records the event store an observed event type belongs to, so the event sequence can be inferred.

protected void CollectEventStore(Type eventType)

Parameters

eventType Type

The event type being observed.

FromAll(Action<IFromAllBuilder<TReadModel>>)

Start building property expressions that apply to all event types in the system. When combined with FromEvery, both sets of mappings apply to all event types.

public TBuilder FromAll(Action<IFromAllBuilder<TReadModel>> builderCallback)

Parameters

builderCallback Action<IFromAllBuilder<TReadModel>>

Callback for building.

Returns

TBuilder

Builder continuation.

FromEvery(Action<IFromEveryBuilder<TReadModel>>)

Start building property expressions that apply to the projection's subscribed event types. When combined with FromAll, these mappings apply to all event types.

public TBuilder FromEvery(Action<IFromEveryBuilder<TReadModel>> builderCallback)

Parameters

builderCallback Action<IFromEveryBuilder<TReadModel>>

Callback for building.

Returns

TBuilder

Builder continuation.

From<TEvent>(Action<IFromBuilder<TReadModel, TEvent>>?)

Start building the from expressions for a specific event type.

public TBuilder From<TEvent>(Action<IFromBuilder<TReadModel, TEvent>>? builderCallback = null)

Parameters

builderCallback Action<IFromBuilder<TReadModel, TEvent>>

Optional callback for building.

Returns

TBuilder

Builder continuation.

Type Parameters

TEvent

Type of event.

Remarks

If using .AutoMap() the properties will be automatically mapped. In many cases you then don't need to provide a builder callback. You can override the mapping by providing a builder callback.

GetFromEventType(EventType)

Gets the existing contract key for a From registration, comparing event types by value.

protected EventType GetFromEventType(EventType eventType)

Parameters

eventType EventType

The event type being registered.

Returns

EventType

The existing key, or a new contract key if the event has not been registered.

Join<TEvent>(Action<IJoinBuilder<TReadModel, TEvent>>?)

Start building a join expressions for a specific event type.

public TBuilder Join<TEvent>(Action<IJoinBuilder<TReadModel, TEvent>>? builderCallback = null)

Parameters

builderCallback Action<IJoinBuilder<TReadModel, TEvent>>

Optional callback for building.

Returns

TBuilder

Builder continuation.

Type Parameters

TEvent

Type of event.

Remarks

If using .AutoMap() the properties will be automatically mapped. In many cases you then don't need to provide a builder callback. You can override the mapping by providing a builder callback.

Nested<TNestedModel>(Expression<Func<TReadModel, TNestedModel?>>, Action<INestedBuilder<TReadModel, TNestedModel>>)

Start building a nested single-object projection for a specific nested model.

public TBuilder Nested<TNestedModel>(Expression<Func<TReadModel, TNestedModel?>> targetProperty, Action<INestedBuilder<TReadModel, TNestedModel>> builderCallback)

Parameters

targetProperty Expression<Func<TReadModel, TNestedModel>>

Expression for expressing the target nullable property.

builderCallback Action<INestedBuilder<TReadModel, TNestedModel>>

Builder callback.

Returns

TBuilder

Builder continuation.

Type Parameters

TNestedModel

Type of nested model.

NoAutoMap()

Disable automatic mapping of event properties to model properties.

public IProjectionBuilder<TReadModel, TBuilder> NoAutoMap()

Returns

IProjectionBuilder<TReadModel, TBuilder>

Builder continuation.

Remarks

Use this to disable the default AutoMap behavior when you need explicit control over all mappings.

RemovedWithJoin<TEvent>(Action<RemovedWithJoinBuilder<TReadModel, TEvent>>?)

Defines what event removes a child through a join. This is optional, your system can chose to not support removal.

public TBuilder RemovedWithJoin<TEvent>(Action<RemovedWithJoinBuilder<TReadModel, TEvent>>? builderCallback = null)

Parameters

builderCallback Action<RemovedWithJoinBuilder<TReadModel, TEvent>>

Optional callback for building.

Returns

TBuilder

Builder continuation.

Type Parameters

TEvent

Type of event.

RemovedWith<TEvent>(Action<RemovedWithBuilder<TReadModel, TEvent>>?)

Defines what event removes a child. This is optional, your system can chose to not support removal.

public TBuilder RemovedWith<TEvent>(Action<RemovedWithBuilder<TReadModel, TEvent>>? builderCallback = null)

Parameters

builderCallback Action<RemovedWithBuilder<TReadModel, TEvent>>

Optional callback for building.

Returns

TBuilder

Builder continuation.

Type Parameters

TEvent

Type of event.

ValidateEventType(Type)

Validates a clause's event type using the requested policy, retaining validation for the effective policy.

protected void ValidateEventType(Type type)

Parameters

type Type

The clause's CLR event type.

Exceptions

TypeIsNotAnEventType

The clause's type is not an event type under the requested policy.

WithInitialValues(Func<TReadModel>)

Sets the initial values to use for a new read model instance.

public TBuilder WithInitialValues(Func<TReadModel> initialValueProviderCallback)

Parameters

initialValueProviderCallback Func<TReadModel>

Callback for building.

Returns

TBuilder

Builder continuation.

Remarks

If one does not provide initial values, the projection engine will leave properties out that hasn't been met by an event projection expression. This will effectively render the properties null and might not be desirable when reading instances of the read models.