Welcome Guest, you are in: Login

dbones docs


Navigation (ArmChair)

Search the wiki

Extending the Pipeline

Modified on 2015/07/08 00:42 by Dave Categorized as Uncategorized


ArmChair has a couple of places where you can extend the functionality. the Pipelines are one of these, in the document we look at extending the pipeline to add some indexing.


There are 2 main pipeline, LoadPipeLine and CommitPipeLine. they allow us to add tasks before and after we commit or load (retrospectively), and effectly take control.

PRE tasks -> Database Command -> POST tasks

out of the box we use these tasks to

  • provide a session level cache
  • tracking instances for change within the session

you could easily implement a application cache, and ensure we minimize any redundant calls to the database, or we could call ElasticSerch once we have updated/saved/deleted an instance.

Task to index to Elasticsearch

When we make changes to objects it may be cool if we updated our index, here is one way we can do this

step 1: create a Task

A simple indexing task, we use the abstract PipeItemMapTask class, which provides each db item in the pipeline 1 at a time, but you could choose to implement direct from the interface IPipeTask.

in the task we inspect the action type of the item and then decide to either delete or update the index, finally we yeild the item back out (this is due to the base class which can be used to MAP a result).

public class IndexTask : PipeItemMapTask<CommitContext>
    private readonly ElasticClient _elasticClient;

    public IndexTask(ElasticClient elasticClient)
        _elasticClient = elasticClient;

    public override IEnumerable<CommitContext> Execute(CommitContext item)

        if (item.ActionType == ActionType.Delete)
        yield return item;

Step 2. Register the task

we need to inform ArmChair of our new task and where to execute this, as we need this POST commit, we add it to that pipeline using the following.

var client = new ElasticClient();
database.Settings.CommitPipeline.RegisterPostCommitTask(context => new IndexTask(client));

Tasks are to be added at the app start-up.
dbones docs, is a sub-site of dbones.co.uk, all its content belongs to dbones.co.uk, this also includes logo's.