Skip to content

Pipeline Hooks

trailmax edited this page Nov 21, 2016 · 3 revisions

Pipeline Hooks

Pipeline hooks are hooks that you can inject your processors into the pipeline of messages. Pipline hooks is defined by IPipelineHook. But you can also implement BasePipelineHook which is an empty abstract class implementing IPipelineHook but you won't have to have empty methods that you don't want to implement.

Mediator takes a list of IPipelineHook so if you are configuring your own DI, make sure you can inject IEnumerable<IPipelineHook>.

Metadata

Default pipeline hook is MetadataPipelineHook that is injected by default when using internal container. This hook stores information about all the messages that come in and when for the saga. This information is stored in Headers["SagaMetadataKey"] and can be accessed by an extension method public static SagaMetadata GetSagaMetadata(this IAccessibleSaga accessibleSaga, IMessageSerialiser messageSerialiser).

Unfortunately this extension needs to know the message serialiser and the usage is not as smooth as expected:

var messageSerialiser = Wireup.UseInternalContainer().Resolve<IMessageSerialiser>();

var simpleSaga = new VerySimpleSaga();// usually get saga from a repository
var metadata = simpleSaga.GetSagaMetadata(messageSerialiser);

Metadata contains information such as date when saga was creaed, when it was last modified and a collection of all the messages that have been issued to this saga.

NSaga does not act on this information, but it is there in case you need to query.