A quick blogpost and a tip I have for developing Sitecore pipelines and processors.
Sitecore loves using pipelines and for good reason. Install a clean Sitecore solution and you’ll get a whole bunch of them. Installing a module? Boom! Get ready for a bunch more.
I assume every Sitecore dev out there knows about pipelines (you should). But just in case, here’s my take:
“Pipelines are just like methods, you put something in and you get something out. The difference is that with pipelines you split the body of the method into different processors.”
I think it’s a great technique they use and allows you to change OOTB Sitecore behavior. You can add your own processors, replace existing ones or just shuffle around a bit. No need to hack the source code, all you need to do is patch the configuration and have it your way.
Installing the Commerce Connect module means you get a bunch of extra pipelines (among other things). The ‘commerce.carts.createCart’ pipeline for instance. Equipped with 3 processors that Sitecore delivered and we added a custom ‘Solution.CreateCart’ processor.
The custom CreateCart processor would go to the external commerce system and request a new cart. All fair and simple, but when looking at the code I saw that processor had 100s of lines and was doing a lot more than just requesting a new cart.
I had to put in quite some effort to reverse engineer and find out what’s was going on. And as I was clustering code by the purpose it served, I had a bit of an epiphany:
“Processors should be kept small and have a single responsibility”
Doing that allowed us to use descriptive names for the processors and putting it to practice gave us some advantages that I find very useful:
And that’s basically my tip: Get to know pipelines. Keep your processors small and their responsibilities smaller. Use descriptive names.