Pranay
Pranay

Reputation: 452

custom pipeline processors and IOC in sitecore mvc

Does sitecore mvc supports custom pipelines as in asp.net web forms?

I have a class which implements RenderLayoutProcessor and override Process method. This class name is added as custom processor in the pipeline by updating the web config section as shown below.

<renderLayout>
    <processor type="Sitecore.Pipelines.PreprocessRequest.CheckIgnoreFlag, Sitecore.Kernel"/>
    <processor type="Sitecore.Pipelines.RenderLayout.PageHandlers, Sitecore.Kernel"/>
    <processor type="Sitecore.Pipelines.RenderLayout.SecurityCheck, Sitecore.Kernel"/>
    <processor type="Sitecore.Pipelines.RenderLayout.InsertRenderings, Sitecore.Kernel"/>

    <processor type="MysitecoreApp.Project.Pipelines.MyProcessor, MysitecoreApp.Project" />

    <processor type="Sitecore.Pipelines.RenderLayout.PageExtenders, Sitecore.Kernel"/>
    <processor type="Sitecore.Pipelines.RenderLayout.ExpandMasterPages, Sitecore.Kernel"/>
    <processor type="Sitecore.Pipelines.RenderLayout.BuildTree, Sitecore.Kernel"/>
    <processor type="Sitecore.Pipelines.RenderLayout.InsertSystemControls, Sitecore.Kernel"/>
    <processor type="Sitecore.Pipelines.RenderLayout.InsertUnusedControls, Sitecore.Kernel"/>
    <processor type="Sitecore.Pipelines.RenderLayout.BrowserCaching, Sitecore.Kernel"/>
</renderLayout>

The process method is triggering for sitecore request(like http://website/sitecore/login) but not for website pages request (like http://website/home).

Below is the class definition.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sitecore.Data.Items;
using Sitecore.Layouts;
using Sitecore.Pipelines.RenderLayout;
using Sitecore.Mvc.Presentation;

namespace MysitecoreApp.Project.Pipelines
{
    public class MyProcessor : RenderLayoutProcessor
    {
        public override void Process(RenderLayoutArgs args)
        {
            var page = Sitecore.Context.Item;
            if (page != null)
            {

            }
        }
    }
}

I am doing this to implement IOC using pipelines (RenderLayout Processor here) as shown in this example

So, will this pipelines concept work in sitecore MVC? If it does not how to implement IOC in Sitecore MVC. I am implementing IOC to have a single footer component which can have multiple rendering items.

Upvotes: 1

Views: 1027

Answers (1)

Jason Horne
Jason Horne

Reputation: 605

The title of this question should be something more along the lines of custom pipeline processors and conditional rendering in sitecore mvc.

The references you listed mention ways to deal with conditional rendering. They don't describe how to implement IOC in Sitecore. If you read here: "The concept is very similar to the ideas of IoC or dependency injection, hence the rather unimaginative name." from this article: http://www.awareweb.com/awareweblegacy/awareblog/inversioncontrol1

There are many ways to implement IOC in Sitecore. I would use Glass mapper and Castle Windsor for IOC.

However I think your actual question is: Does the renderLayout pipeline work with MVC views? - Answer is no. Try the mvc.renderRendering pipeline. Investigate the mvc pipelines in the Sitecore.Mvc.config (https://github.com/HedgehogDevelopment/sitecore-mvc/blob/master/MvcNewsApp/App_Config/Include/Sitecore.Mvc.config)

Upvotes: 0

Related Questions