All about Sitecore Commerce pipelines (Part 1)
As we all know Sitecore Commerce is based on .NET Core and traditional Sitecore config patches is a thing of the past at least for commerce webapps.
In this article I’ll try to give a broad overview of the pipelines for Sitecore Commerce — what they are, how to use them and create new one.
What are Sitecore Commerce pipelines?
Same as Sitecore in Sitecore Commerce pipelines are defined as a function that takes an arguments and returns the result by iterating its blocks.
However opposing to previously defining pipeline in config patches now we define pipelines in code.
To do so we have to implement the IConfigureSitecore interface and override ConfigureServices method as below.
Configuring existing pipelines
In Sitecore Commerce we can both create new and change existing pipeline.
To extend existing Sitecore Commerce pipeline we should call ConfigurePipeline method with pipeline interface as a type parameter.
Creating a new block for pipeline is as easy as implementing a new class that inherits from the PipelineBlock class and defining three arguments — block input argument type, output argument type and context class which usually is CommercePipelineExecutionContext.
However its important to keep in mind which types are returned by the block during pipeline execution and which one is expected by the next block (or are returned by the pipeline if the block is the last one). Otherwise we would get error during pipeline execution as Sitecore wouldnt be able to cast the input/output parameter types.
We can use extension methods and same as in patch files use modifiers to configure the order of our new block or remove the existing one.
Listing the pipelines
Is there an alternative to showconfig.aspx to view the pipeline configuration? The answer is yes.
For this on every commerce engine startup Sitecore Commerce creates a NodeConfiguration log that contains all configured pipeline and their blocks and its parameters in one place.
Now, here is the cool stuff you can do knowing how to extend pipelines!
- Add new sections to Sitecore Commerce BizFX tools
- Implement a custom payment provider (Sitecore Commerce already comes with an example how to do that — see Plugin.Sample.Payments.Braintree project in the sample Commerce Engine solution)
- Extend Sitecore Commerce with new APIs (see my previous post on this here) and many many more stuff….