Pipelines are one of the most essential parts of Sitecore and creating your own custom pipeline in Sitecore makes your code extremely flexible for both you and others. It is extremely easy to create and run a custom pipeline as this post will show.
Defining the pipeline
A pipeline consist is a set of processor classes which each has a method called Process which takes one argument of PipelineArgs or a derived class.
To configure a pipeline create a new .config file in the include folder:
1 2 3 4 5 6 7 8 9 |
<configuration> <sitecore> <pipelines> <somePipeline> </somePipeline> </pipelines> </sitecore> </configuration> |
Create a class derived from PipelineArgsĀ which suits your implementation needs.
1 2 3 4 |
public class SomePipelineArgs : PipelineArgs { public string Result { get; set; } } |
Create the processor class(es):
1 2 3 4 5 6 7 8 9 10 11 12 |
public class SomeProcessor { public void Process(SomePipelineArgs args) { args.Result = GetResult(); } private string GetResult() { return "Hellow world"; } } |
Insert them in your config.
1 2 3 |
<somePipeline> <processor type="[NAMESPACE].SomeProcessor, [ASSEMBLY]" /> </somePipeline> |
Calling the pipeline
To call the pipeline we use the CorePipeline.Run method as follows:
1 2 3 |
var pipelineArgs = new SomePipelineArgs(); CorePipeline.Run("somePipeline", pipelineArgs); Log.Info(args.Result, this); |
This is how simple it is to create a pipeline.
Anders Laub Christoffersen
Anders has been working with Sitecore for over a decade and has in this time been the lead developer and architect on several large scale enterprise solutions all around the world. Anders was appointed the title of Sitecore Technical MVP in 2014 and has been re-appointed the title every year since then.
- Web |
- More Posts
2 thoughts on “Creating a custom pipeline in Sitecore”