Class ReducerTypeExtensions

Namespace
Cratis.Chronicle.Reducers
Assembly
Cratis.Chronicle.dll

Extension methods for working with reducer types.

public static class ReducerTypeExtensions
Inheritance
ReducerTypeExtensions
Inherited Members

Methods

GetEventSequenceId(Type, string?)

Get the event sequence id for a reducer type.

public static EventSequenceId GetEventSequenceId(this Type type, string? currentEventStoreName = null)

Parameters

type Type

Type to get from.

currentEventStoreName string

The name of the event store the reducer is registered in. When provided, event types that belong to the same store will resolve to the event log rather than an inbox sequence.

Returns

EventSequenceId

The EventSequenceId for the type.

Exceptions

MultipleEventStoresDefined

Thrown when the reducer handles event types from multiple event stores.

EventStoreCannotBeCombinedWithExplicitEventSequence

Thrown when EventStoreAttribute is combined with explicit event sequence configuration.

GetHandlerEventTypes(Type)

Get all event types used in the handler method signatures of a reducer type.

public static IEnumerable<Type> GetHandlerEventTypes(this Type type)

Parameters

type Type

Type to get from.

Returns

IEnumerable<Type>

All event types found as first parameters in handler methods.

Remarks

A handler method is any non-special public or non-public instance method whose first parameter type carries the EventTypeAttribute. Duplicates are removed so each event type appears at most once.

GetReadModelType(Type)

Get the type of the read model for a reducer.

public static Type GetReadModelType(this Type type)

Parameters

type Type

Reducer type to get for.

Returns

Type

Type of read model.

GetReducerId(Type)

Get the reducer id for a type.

public static ReducerId GetReducerId(this Type type)

Parameters

type Type

Type to get from.

Returns

ReducerId

The ReducerId for the type.

HasExplicitEventSequence(Type)

Get whether a reducer type has an explicit event sequence set.

public static bool HasExplicitEventSequence(this Type type)

Parameters

type Type

Type to check.

Returns

bool

true if an explicit event sequence is configured; otherwise false.

HasNonNullableCurrentReadModelParameter(MethodInfo)

Check whether a reducer-shaped MethodInfo declares its current read model parameter as non-nullable.

public static bool HasNonNullableCurrentReadModelParameter(this MethodInfo methodInfo)

Parameters

methodInfo MethodInfo

MethodInfo to check.

Returns

bool

True if the current read model parameter is statically non-nullable, false if not.

Remarks

The current read model is null for the event that brings an instance into existence, so a non-nullable declaration is a claim the reducer cannot keep. A method declared in a #nullable disable context makes no claim either way and is not reported.

HasReducerMethodShape(MethodInfo, Type, IEnumerable<Type>)

Check if a MethodInfo is shaped like a reducer method, without considering the nullability of its current read model parameter.

public static bool HasReducerMethodShape(this MethodInfo methodInfo, Type readModelType, IEnumerable<Type> eventTypes)

Parameters

methodInfo MethodInfo

MethodInfo to check.

readModelType Type

Type of read model.

eventTypes IEnumerable<Type>

Known event types in the process.

Returns

bool

True if it has the shape of a reducer method, false if not.

Remarks

This is the signature match on its own - return type, event type as first parameter, the read model as second and an optional EventContext as third. A method that matches this but declares its current read model as non-nullable is a reducer method the author got wrong, not a method that happens to look similar, which is what lets ReducerMethodCurrentReadModelMustBeNullable report it instead of silently dropping it from dispatch.

IsActive(Type)

Get whether a reducer is active.

public static bool IsActive(this Type type)

Parameters

type Type

Type to get from.

Returns

bool

True if it is, false if not.

IsReducerMethod(MethodInfo, Type, IEnumerable<Type>)

Check if a MethodInfo is a reducer method.

public static bool IsReducerMethod(this MethodInfo methodInfo, Type readModelType, IEnumerable<Type> eventTypes)

Parameters

methodInfo MethodInfo

MethodInfo to check.

readModelType Type

Type of read model.

eventTypes IEnumerable<Type>

Known event types in the process.

Returns

bool

True if it is a reducer method, false if not.

Remarks

The following are considered valid reducer method signatures.

Task<TReadModel> {MethodName}(TEvent event, TReadModel? initial, EventContext context) Task<TReadModel> {MethodName}(TEvent event, TReadModel? initial) TReadModel {MethodName}(TEvent event, TReadModel? current, EventContext context) TReadModel {MethodName}(TEvent event, TReadModel? current)