Table of Contents

Class ProjectionBuilder<TModel, TBuilder>

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

Represents a base projection builder.

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

Type Parameters

TModel

Type of model to build for.

TBuilder

Type of actual builder.

Inheritance
ProjectionBuilder<TModel, TBuilder>
Implements
IProjectionBuilder<TModel, TBuilder>
Derived
Inherited Members

Remarks

Initializes a new instance of the ProjectionBuilder<TModel, TBuilder> class.

Constructors

ProjectionBuilder(IEventTypes, IJsonSchemaGenerator, JsonSerializerOptions, bool)

Represents a base projection builder.

public ProjectionBuilder(IEventTypes eventTypes, IJsonSchemaGenerator schemaGenerator, JsonSerializerOptions jsonSerializerOptions, bool autoMap)

Parameters

eventTypes IEventTypes

IEventTypes for providing event type information.

schemaGenerator IJsonSchemaGenerator

IJsonSchemaGenerator for generating JSON schemas.

jsonSerializerOptions JsonSerializerOptions

The JsonSerializerOptions to use for any JSON serialization.

autoMap bool

Whether to automatically map properties.

Remarks

Initializes a new instance of the ProjectionBuilder<TModel, TBuilder> class.

Fields

_autoMap

protected bool _autoMap

Field Value

bool

_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

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>

_modelName

protected string _modelName

Field Value

string

_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<TModel, TBuilder> AutoMap()

Returns

IProjectionBuilder<TModel, TBuilder>

Builder continuation.

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

Start building the children projection for a specific child model.

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

Parameters

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

Expression for expressing the target property.

builderCallback Action<IChildrenBuilder<TModel, TChildModel>>

Builder callback.

Returns

TBuilder

Builder continuation.

Type Parameters

TChildModel

Type of nested child model.

FromEvery(Action<IFromEveryBuilder<TModel>>)

Start building property expressions that applies for every events being projected from.

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

Parameters

builderCallback Action<IFromEveryBuilder<TModel>>

Callback for building.

Returns

TBuilder

Builder continuation.

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

Start building the from expressions for a specific event type.

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

Parameters

builderCallback Action<IFromBuilder<TModel, 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.

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

Start building a join expressions for a specific event type.

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

Parameters

builderCallback Action<IJoinBuilder<TModel, 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.

RemovedWithJoin<TEvent>(Action<RemovedWithJoinBuilder<TModel, 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<TModel, TEvent>>? builderCallback = null)

Parameters

builderCallback Action<RemovedWithJoinBuilder<TModel, TEvent>>

Optional callback for building.

Returns

TBuilder

Builder continuation.

Type Parameters

TEvent

Type of event.

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

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

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

Parameters

builderCallback Action<RemovedWithBuilder<TModel, TEvent>>

Optional callback for building.

Returns

TBuilder

Builder continuation.

Type Parameters

TEvent

Type of event.

WithInitialValues(Func<TModel>)

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

public TBuilder WithInitialValues(Func<TModel> initialValueProviderCallback)

Parameters

initialValueProviderCallback Func<TModel>

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 models.