Skip to content

Handlers

Although handlers are very similar to adapters, their conceptual purpose is different: to handle data. That means the handler is the final destination of the data and any business logic should be applied here and not on an adapter. Handlers are executed at the end of the pipeline and do not forward data. Unlike adapters, multiple handlers can be executed for the same data. They are executed sequentially in the order they are registered.

graph LR;
    in[/Data In/] --> H1[Handler]
    in -.-> H2[Handler]

Implementing a Handler

Similarly to adapters, unless you have very specific needs, you should inherit your handler from the ChannelHandler<T> class and not implementing the IChannelHandler interface directly.

public class MyChannelHandler : ChannelHandler<MyData>
{
    public override Task ExecuteAsync( IChannelContext context, MyData data, CancellationToken cancellationToken )
    {
        // implement your handler here
    }
}