Interface IReactorBuilder
- Namespace
- Cratis.Chronicle.Reactors
- Assembly
- Cratis.Chronicle.dll
Defines a builder for declaring a reactor fluently, with handlers for the events it reacts to.
public interface IReactorBuilder
- Extension Methods
Remarks
Handlers are awaited, and an event is only acknowledged once every handler for it has completed. A handler that throws or returns a failed task fails the event's partition, exactly as a failing method on a discovered reactor does.
When an event has typed handlers and the reactor also has catch-all handlers, the typed handlers run first, in the order they were declared, followed by the catch-all handlers in the order they were declared.
Methods
NotReplayable()
Disables replay for the reactor, for handlers whose side effects must not be repeated.
IReactorBuilder NotReplayable()
Returns
- IReactorBuilder
The builder for continuation.
OnEventSequence(EventSequenceId)
Selects the event sequence to observe. Defaults to the event log.
IReactorBuilder OnEventSequence(EventSequenceId eventSequenceId)
Parameters
eventSequenceIdEventSequenceIdThe event sequence.
Returns
- IReactorBuilder
The builder for continuation.
On<TEvent>(Action<TEvent, EventContext>)
Handle a specific event type, with its EventContext.
IReactorBuilder On<TEvent>(Action<TEvent, EventContext> handler)
Parameters
handlerAction<TEvent, EventContext>The handler receiving the event and its context.
Returns
- IReactorBuilder
The builder for continuation.
Type Parameters
TEventThe event type to handle. Subscribes the reactor to this event type only.
Exceptions
- TypeIsNotAnEventType
Thrown when
TEventis not a known event type.
On<TEvent>(Action<TEvent>)
Handle a specific event type.
IReactorBuilder On<TEvent>(Action<TEvent> handler)
Parameters
handlerAction<TEvent>The handler receiving the event.
Returns
- IReactorBuilder
The builder for continuation.
Type Parameters
TEventThe event type to handle. Subscribes the reactor to this event type only.
Exceptions
- TypeIsNotAnEventType
Thrown when
TEventis not a known event type.
On<TEvent>(Func<TEvent, EventContext, Task>)
Handle a specific event type asynchronously, with its EventContext.
IReactorBuilder On<TEvent>(Func<TEvent, EventContext, Task> handler)
Parameters
handlerFunc<TEvent, EventContext, Task>The handler receiving the event and its context.
Returns
- IReactorBuilder
The builder for continuation.
Type Parameters
TEventThe event type to handle. Subscribes the reactor to this event type only.
Exceptions
- TypeIsNotAnEventType
Thrown when
TEventis not a known event type.
On<TEvent>(Func<TEvent, Task>)
Handle a specific event type asynchronously.
IReactorBuilder On<TEvent>(Func<TEvent, Task> handler)
Parameters
Returns
- IReactorBuilder
The builder for continuation.
Type Parameters
TEventThe event type to handle. Subscribes the reactor to this event type only.
Exceptions
- TypeIsNotAnEventType
Thrown when
TEventis not a known event type.
Subscribe(Action<object, EventContext>)
Handle every event, whatever its type. This makes the reactor an all-events subscription.
IReactorBuilder Subscribe(Action<object, EventContext> handler)
Parameters
handlerAction<object, EventContext>The handler receiving each event and its context.
Returns
- IReactorBuilder
The builder for continuation.
Remarks
The subscription covers every event type this client knows when the reactor is defined - the event types discovered in the client's artifacts. An event type the client does not know cannot be turned into an object to hand to the handler, so it is not part of the subscription; nor is an event type that becomes known only after the reactor was defined. EventTypes tells exactly which event types that is.
Subscribe(Func<object, EventContext, Task>)
Handle every event asynchronously, whatever its type. This makes the reactor an all-events subscription.
IReactorBuilder Subscribe(Func<object, EventContext, Task> handler)
Parameters
handlerFunc<object, EventContext, Task>The handler receiving each event and its context.
Returns
- IReactorBuilder
The builder for continuation.
Remarks
The subscription covers the same event types as Subscribe(Action<object, EventContext>) describes.