When does Sitecore run the initialize pipeline?

sitecore

Solution

I decided to try adding some debugging to a clean installation of Sitecore 7.2. I created the following simple class:

using Sitecore.Diagnostics;
using Sitecore.Pipelines;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;

namespace SCMVC72.Pipelines
{
    public class DebugStackTrace
    {
        public void Process(PipelineArgs args)
        {
            StackTrace st = new StackTrace(); 
            Log.Info(string.Empty, (object)this);
            Log.Info("*********************************************************************", (object)this);
            Log.Info("Debug StackTrace", (object)this);
            Log.Info(st.ToString(), (object)this);
            Log.Info("*********************************************************************", (object)this);
        }
    }
}

And the I added the following config file in the `App_Config\Include` folder:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <initialize>
        <processor type="SCMVC72.Pipelines.DebugStackTrace, SCMVC72" 
                   patch:before="processor[@type='Sitecore.Pipelines.Loader.ShowVersion, Sitecore.Kernel']" />
      </initialize>
    </pipelines>
  </sitecore>
</configuration>

On application restart, This is the output I got in the logs:

5764 14:38:08 INFO  HttpModule is being initialized
5764 14:38:08 INFO  
5764 14:38:08 INFO  *********************************************************************
5764 14:38:08 INFO  Debug StackTrace
5764 14:38:08 INFO     at SCMVC72.Pipelines.DebugStackTrace.Process(PipelineArgs args)
   at (Object , Object[] )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Nexus.Web.HttpModule.Application_Start()
   at Sitecore.Nexus.Web.HttpModule.Init(HttpApplication app)
   at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
   at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
   at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
   at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)
5764 14:38:08 INFO  *********************************************************************

Which was output right befor the famous:

5764 14:38:08 INFO  
5764 14:38:08 INFO  **********************************************************************
5764 14:38:08 INFO  **********************************************************************
5764 14:38:08 INFO  Sitecore started
5764 14:38:08 INFO  Sitecore.NET 7.2 (rev. 140228)

This confirms what HRH John West said when he wrote that "this happens in one of the obfuscated assemblies" - Sitecore.Nexus, to be more precise.

Problem

I have been peeking through the Sitecore.Kernel but can't seem to find the place where Sitecore runs the Initialize pipeline. Does it run on every page request or only once on application start? Can you point me to the exact place where the Run method is being called for this pipeline? update There reason I ended up asking this question is because I was tracing back, in Sitecore's code, the execution of the `mvc.requestBegin` pipeline. This is what I found: - the `Initialize` pipeline runs the `InitializeRoutes` processor... - `Sitecore.Mvc.Pipelines.Loader.InitializeRoutes.Process(PipelineArgs args)` calls... - `Sitecore.Mvc.Pipelines.Loader.InitializeRoutes.RegisterRoutes(RouteCollection routes, PipelineArgs args)` calls... - `Sitecore.Mvc.Pipelines.Loader.InitializeRoutes.SetRouteHandlers(RouteCollection routes, PipelineArgs args)` creates new `RouteHandlerWrapper` objects here things get a bit fuzzy... - `Sitecore.Mvc.Routing.RouteHandlerWrapper.GetHttpHandler(RequestContext requestContext)` returns `(IHttpHandler) new RouteHttpHandler` and then, finally... - `Sitecore.Mvc.Routing.RouteHttpHandler.ProcessRequest(HttpContext context)` calls... - `Sitecore.Mvc.Routing.RouteHttpHandler.BeginRequest()` runs `mvc.requestBegin` pipeline

Original source