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
TReadModelType of read model to build for.
TBuilderType of actual builder.
- Inheritance
-
ProjectionBuilder<TReadModel, TBuilder>
- Implements
-
IProjectionBuilder<TReadModel, TBuilder>
- Derived
- Inherited Members
Constructors
ProjectionBuilder(INamingPolicy, IEventTypes, JsonSerializerOptions, AutoMap)
Represents a base projection builder.
public ProjectionBuilder(INamingPolicy namingPolicy, IEventTypes eventTypes, JsonSerializerOptions jsonSerializerOptions, AutoMap autoMap)
Parameters
namingPolicyINamingPolicyThe INamingPolicy to use for converting names during serialization.
eventTypesIEventTypesIEventTypes for providing event type information.
jsonSerializerOptionsJsonSerializerOptionsThe JsonSerializerOptions to use for any JSON serialization.
autoMapAutoMapAutoMap behavior for properties - defaults to Enabled at top level.
Fields
_autoMap
protected AutoMap _autoMap
Field Value
_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
_joinDefinitions
protected readonly Dictionary<EventType, JoinDefinition> _joinDefinitions
Field Value
- Dictionary<EventType, JoinDefinition>
_observedEventStores
protected readonly List<string> _observedEventStores
Field Value
_readModelIdentifier
protected ReadModelIdentifier _readModelIdentifier
Field Value
_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.
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
targetPropertyExpression<Func<TReadModel, IEnumerable<TChildModel>>>Expression for expressing the target property.
builderCallbackAction<IChildrenBuilder<TReadModel, TChildModel>>Builder callback.
Returns
- TBuilder
Builder continuation.
Type Parameters
TChildModelType of nested child model.
FromEvery(Action<IFromEveryBuilder<TReadModel>>)
Start building property expressions that applies for every events being projected from.
public TBuilder FromEvery(Action<IFromEveryBuilder<TReadModel>> builderCallback)
Parameters
builderCallbackAction<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
builderCallbackAction<IFromBuilder<TReadModel, TEvent>>Optional callback for building.
Returns
- TBuilder
Builder continuation.
Type Parameters
TEventType 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<TReadModel, TEvent>>?)
Start building a join expressions for a specific event type.
public TBuilder Join<TEvent>(Action<IJoinBuilder<TReadModel, TEvent>>? builderCallback = null)
Parameters
builderCallbackAction<IJoinBuilder<TReadModel, TEvent>>Optional callback for building.
Returns
- TBuilder
Builder continuation.
Type Parameters
TEventType 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.
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
builderCallbackAction<RemovedWithJoinBuilder<TReadModel, TEvent>>Optional callback for building.
Returns
- TBuilder
Builder continuation.
Type Parameters
TEventType 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
builderCallbackAction<RemovedWithBuilder<TReadModel, TEvent>>Optional callback for building.
Returns
- TBuilder
Builder continuation.
Type Parameters
TEventType of event.
WithInitialValues(Func<TReadModel>)
Sets the initial values to use for a new read model instance.
public TBuilder WithInitialValues(Func<TReadModel> initialValueProviderCallback)
Parameters
initialValueProviderCallbackFunc<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.