Interface IReactorSideEffectHandler

Namespace
Cratis.Chronicle.Reactors.SideEffects
Assembly
Cratis.Chronicle.dll

Defines a handler that can process a value returned from a reactor handler method and produce side effects.

public interface IReactorSideEffectHandler
Extension Methods

Remarks

Implement this interface and register it in the DI container to extend the set of return types that reactor handler methods can produce. The framework discovers all registered IReactorSideEffectHandler instances and delegates to those whose CanHandle(ReactorContext, IEventStore, object) method returns true.

Methods

CanHandle(ReactorContext, IEventStore, object)

Determines whether this handler can process the given return value.

bool CanHandle(ReactorContext reactorContext, IEventStore eventStore, object value)

Parameters

reactorContext ReactorContext

The ReactorContext for the reactor invocation.

eventStore IEventStore

The IEventStore the reactor is running under.

value object

The value returned by the reactor handler method.

Returns

bool

true if this handler can process the value; otherwise false.

Remarks

The event store is passed per call rather than captured, because everything it exposes — the event type registry in particular — belongs to the namespace the resolving scope named. A handler that holds one is answering for whichever namespace happened to build it first.

Defaults to the event-store-less overload so a handler written against the previous contract keeps working unchanged. Implementations that need event-store-specific state can override this overload while retaining the previous one for callers compiled against the published contract.

CanHandle(ReactorContext, object)

Determines whether this handler can process the given return value.

bool CanHandle(ReactorContext reactorContext, object value)

Parameters

reactorContext ReactorContext

The ReactorContext for the reactor invocation.

value object

The value returned by the reactor handler method.

Returns

bool

true if this handler can process the value; otherwise false.

CanHandleReturnType(Type)

Determines whether a synchronous reactor return type is supported by this handler.

bool CanHandleReturnType(Type type)

Parameters

type Type

The declared return type of the reactor method.

Returns

bool

true if this handler claims the type; otherwise false.

Remarks

Defaults to false to preserve existing handler implementations.

Handle(ReactorContext, IEventStore, object)

Processes the return value, typically by appending one or more events to an event sequence.

Task<Result<ReactorSideEffectFailure>> Handle(ReactorContext reactorContext, IEventStore eventStore, object value)

Parameters

reactorContext ReactorContext

The ReactorContext for the reactor invocation.

eventStore IEventStore

The IEventStore to use for appending events.

value object

The value returned by the reactor handler method.

Returns

Task<Result<ReactorSideEffectFailure>>

A Task representing the asynchronous operation.