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
- Extension Methods
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
_fromDefinitions
protected readonly Dictionary<EventType, FromDefinition> _fromDefinitions
Field Value
_fromDerivativesDefinitions
Holds grouped registrations already expanded into _fromDefinitions. Do not also emit these through FromEvery.
protected readonly List<FromDerivativesDefinition> _fromDerivativesDefinitions
Field Value
_fromEveryDefinition
protected FromEveryDefinition _fromEveryDefinition
Field Value
_initialValues
protected JsonObject _initialValues
Field Value
_joinDefinitions
protected readonly Dictionary<EventType, JoinDefinition> _joinDefinitions
Field Value
_nestedDefinitions
protected readonly Dictionary<PropertyPath, ChildrenDefinition> _nestedDefinitions
Field Value
_noAutoMapProperties
protected readonly IReadOnlyList<string> _noAutoMapProperties
Field Value
_observedEventStores
protected readonly List<string> _observedEventStores
Field Value
_readModelIdentifier
protected ReadModelIdentifier _readModelIdentifier
Field Value
_removedWithDefinitions
protected readonly Dictionary<EventType, RemovedWithDefinition> _removedWithDefinitions
Field Value
_removedWithJoinDefinitions
protected readonly Dictionary<EventType, RemovedWithJoinDefinition> _removedWithJoinDefinitions
Field Value
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
generationDeliveryEventGenerationDeliveryThe 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
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.
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
eventTypeTypeThe 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
builderCallbackAction<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
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.
GetFromEventType(EventType)
Gets the existing contract key for a From registration, comparing event types by value.
protected EventType GetFromEventType(EventType eventType)
Parameters
eventTypeEventTypeThe 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
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.
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
targetPropertyExpression<Func<TReadModel, TNestedModel>>Expression for expressing the target nullable property.
builderCallbackAction<INestedBuilder<TReadModel, TNestedModel>>Builder callback.
Returns
- TBuilder
Builder continuation.
Type Parameters
TNestedModelType 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
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.
ValidateEventType(Type)
Validates a clause's event type using the requested policy, retaining validation for the effective policy.
protected void ValidateEventType(Type type)
Parameters
typeTypeThe 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
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.