<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 <title>Andrew Cherry on Software and Technology</title>
 <link href="http://xyncro.com/atom.xml" rel="self"/>
 <link href="http://xyncro.com/"/>
 <updated>2011-10-13T08:55:03-07:00</updated>
 <id>http://www.xyncro.com/</id>
 <author>
   <name>Andrew Cherry</name>
   <email>andrew@xyncro.com</email>
 </author>
 
 <entry>
   <title>Orchard Shell Activation</title>
   <link href="http://xyncro.com/orchard/2011/09/13/orchard-shell-activation.html"/>
   <updated>2011-09-13T00:00:00-07:00</updated>
   <id>http://xyncro.com/orchard/2011/09/13/orchard-shell-activation</id>
   <content type="html">&lt;p&gt;This is part 3 of a series on &lt;a href='/orchard/2011/08/26/orchard-internals-series.html'&gt;Orchard Internals&lt;/a&gt;. See &lt;a href='/orchard/2011/08/26/orchard-internals-series.html'&gt;the introductory post&lt;/a&gt; for previous posts (and a full post listing).&lt;/p&gt;

&lt;h2 id='overview'&gt;Overview&lt;/h2&gt;

&lt;p&gt;In &lt;a href='/orchard/2011/09/01/orchard-host.html'&gt;part 2&lt;/a&gt; we looked at the initialization of the Orchard host, and how that created new shell contexts and shells to host Orchard sites. We left off at the point where a host was pretty much complete and Orchard was ready to begin serving requests, but we skipped over the activation of our actual shells. We&amp;#8217;re going to look in there in this article, and see what happens on that call to &lt;code&gt;Activate&lt;/code&gt; on our shell once it&amp;#8217;s been created.&lt;/p&gt;

&lt;h2 id='defaultorchardshell'&gt;DefaultOrchardShell&lt;/h2&gt;

&lt;p&gt;We can see from our dependency registrations that our instance of &lt;code&gt;IOrchardShell&lt;/code&gt; is going to be an instance of &lt;code&gt;DefaultOrchardShell&lt;/code&gt;, which is found in &lt;strong&gt;Environment/DefaultOrchardShell.cs&lt;/strong&gt;. We&amp;#8217;ll take a look at that now. First of all, let&amp;#8217;s look at the constructor:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;public&lt;/span&gt; &lt;span class='nf'&gt;DefaultOrchardShell&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;
    &lt;span class='n'&gt;Func&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;Owned&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;IOrchardShellEvents&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;eventsFactory&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='n'&gt;IEnumerable&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;IRouteProvider&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;routeProviders&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='n'&gt;IRoutePublisher&lt;/span&gt; &lt;span class='n'&gt;routePublisher&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='n'&gt;IEnumerable&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;IModelBinderProvider&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;modelBinderProviders&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='n'&gt;IModelBinderPublisher&lt;/span&gt; &lt;span class='n'&gt;modelBinderPublisher&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;_eventsFactory&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;eventsFactory&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='n'&gt;_routeProviders&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;routeProviders&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='n'&gt;_routePublisher&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;routePublisher&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='n'&gt;_modelBinderProviders&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;modelBinderProviders&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='n'&gt;_modelBinderPublisher&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;modelBinderPublisher&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;

    &lt;span class='n'&gt;Logger&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;NullLogger&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Instance&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We wouldn&amp;#8217;t normally be too interested in this &amp;#8212; it&amp;#8217;s standard constructor injection in IoC. But it&amp;#8217;s worth remembering that this instance of &lt;code&gt;DefaultOrchardShell&lt;/code&gt; was resolved in the shell scope, so those dependencies are shell scoped dependencies. It&amp;#8217;s also worth remembering that the dependencies at the shell level aren&amp;#8217;t necessarily ones that have been registered in the traditional way, as seen in &lt;code&gt;OrchardStarter&lt;/code&gt;. They&amp;#8217;ve probably been registered in the Orchard way, by finding dependencies that implement &lt;code&gt;IDependency&lt;/code&gt; and the related family of interfaces. This means that we can&amp;#8217;t look up dependencies quite as easily, as they&amp;#8217;re now being registered dynamically.&lt;/p&gt;

&lt;p&gt;For example, let&amp;#8217;s look at the instance of &lt;code&gt;IRoutePublisher&lt;/code&gt; which is a constructor dependency. That interface looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;namespace&lt;/span&gt; &lt;span class='nn'&gt;Orchard.Mvc.Routes&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;public&lt;/span&gt; &lt;span class='k'&gt;interface&lt;/span&gt; &lt;span class='n'&gt;IRoutePublisher&lt;/span&gt; &lt;span class='p'&gt;:&lt;/span&gt; &lt;span class='n'&gt;IDependency&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='k'&gt;void&lt;/span&gt; &lt;span class='nf'&gt;Publish&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;IEnumerable&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;RouteDescriptor&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;routes&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can see that it implements IDependency, so that any class which implements that interface will be automatically registered as a dependency. In this case that class is &lt;code&gt;RoutePublisher&lt;/code&gt; in the &lt;strong&gt;Orchard.Framework&lt;/strong&gt; project, found in &lt;strong&gt;Mvc/Routes/RoutePublisher.cs&lt;/strong&gt;. It was dynamically registered as a dependency when we were creating our shell lifetime scope, and when we resolved our shell instance, it was resolved from that scope. This is a good thing to remember and be aware of.&lt;/p&gt;

&lt;h2 id='activation'&gt;Activation&lt;/h2&gt;

&lt;p&gt;Once we&amp;#8217;ve got our &lt;code&gt;DefaultOrchardShell&lt;/code&gt; instance, the host is going to call &lt;code&gt;Activate&lt;/code&gt; when we&amp;#8217;re initializing our host, as we&amp;#8217;ve seen in previous posts. Happily, the &lt;code&gt;Activate&lt;/code&gt; method looks pretty straightforward, like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;public&lt;/span&gt; &lt;span class='k'&gt;void&lt;/span&gt; &lt;span class='nf'&gt;Activate&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;_routePublisher&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Publish&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;_routeProviders&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;SelectMany&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;provider&lt;/span&gt; &lt;span class='p'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;provider&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;GetRoutes&lt;/span&gt;&lt;span class='p'&gt;()));&lt;/span&gt;
    &lt;span class='n'&gt;_modelBinderPublisher&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Publish&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;_modelBinderProviders&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;SelectMany&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;provider&lt;/span&gt; &lt;span class='p'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;provider&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;GetModelBinders&lt;/span&gt;&lt;span class='p'&gt;()));&lt;/span&gt;

    &lt;span class='k'&gt;using&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;events&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_eventsFactory&lt;/span&gt;&lt;span class='p'&gt;())&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;events&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Value&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Activated&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Not too much going on &amp;#8212; publishing the routes and model binders which are part of our site. (We also do some work with events, (&lt;code&gt;IOrchardShellEvents&lt;/code&gt;) which we&amp;#8217;ll look at later on. Before then, let&amp;#8217;s look at how routes work within a shell.&lt;/p&gt;

&lt;h2 id='routes_and_shells'&gt;Routes and Shells&lt;/h2&gt;

&lt;p&gt;As we can see, routes are published on a per shell basis, so routes can be different between tenants. We also know from the &lt;a href='/orchard/2011/08/30/orchard-startup-process.html'&gt;first article&lt;/a&gt; that routes are not registered as part of our main web application as they often are in ASP.NET MVC web applications.&lt;/p&gt;

&lt;p&gt;Routes in Orchard are registered by implementing &lt;code&gt;IRouteProvider&lt;/code&gt; in modules. Looking at that interface, unsurprisingly it implements &lt;code&gt;IDependency&lt;/code&gt;. This means that &lt;code&gt;DefaultOrchardShell&lt;/code&gt; can take a constructor dependency on &lt;code&gt;IEnumerable&amp;lt;IRouteProvider&amp;gt;&lt;/code&gt; and get back all of the routes which need to be registered for all modules, thanks to the IoC implementation scanning all of the loaded modules.&lt;/p&gt;

&lt;p&gt;It simply calls &lt;code&gt;GetRoutes&lt;/code&gt; on each of them and then sends the resulting collection of &lt;code&gt;RouteDescriptor&lt;/code&gt; instances off to the route publisher to be published (registered) for our shell.&lt;/p&gt;

&lt;p&gt;There&amp;#8217;s a bit more though. Routes in an ASP.NET MVC 3 application are global &amp;#8212; there&amp;#8217;s only one actual site here, despite the multi-tenancy possibilities, so how are we making sure that only the routes for our shell are used to get to our tenant?&lt;/p&gt;

&lt;p&gt;This is where Orchard can go back and take advantage of some of the extensibility options built in to the ASP.NET MVC 3 framework. When you register a route in ASP.NET MVC 3, the method signature on the &lt;code&gt;RouteCollection&lt;/code&gt; actually takes a &lt;code&gt;RouteBase&lt;/code&gt;, which can be extended. So the route publisher actually orders the &lt;code&gt;RouteDescriptor&lt;/code&gt; instances it has (by the Priority property which you can set when registering routes &amp;#8212; as the order of routes is important in ASP.NET MVC 3) and then turns each route descriptor in to an instance of &lt;code&gt;ShellRoute&lt;/code&gt;, which extends &lt;code&gt;RouteBase&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s worth seeing what &lt;code&gt;ShellRoute&lt;/code&gt; is and how it works as the principle could be applied elsewhere. It can be found in &lt;strong&gt;Mvc/Routes/ShellRoute.cs&lt;/strong&gt; in the &lt;strong&gt;Orchard.Framework&lt;/strong&gt; project.&lt;/p&gt;

&lt;p&gt;The crucial points in here are that it overrides &lt;code&gt;GetRouteData&lt;/code&gt; and &lt;code&gt;GetVirtualPath&lt;/code&gt; to ensure that the route only responds and matches if the request is for the right shell. It does this with the following code at the start of each of those methods:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='c1'&gt;// locate appropriate shell settings for request&lt;/span&gt;
&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;settings&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_runningShellTable&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Match&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;httpContext&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

&lt;span class='c1'&gt;// only proceed if there was a match, and it was for this client&lt;/span&gt;
&lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;settings&lt;/span&gt; &lt;span class='p'&gt;==&lt;/span&gt; &lt;span class='k'&gt;null&lt;/span&gt; &lt;span class='p'&gt;||&lt;/span&gt; &lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Name&lt;/span&gt; &lt;span class='p'&gt;!=&lt;/span&gt; &lt;span class='n'&gt;_shellSettings&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Name&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='k'&gt;null&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It&amp;#8217;s checking to see whether there&amp;#8217;s a match between the settings of the current request, which it can get from the running shells table which we saw previously, and the shell settings for this particular shell (&lt;code&gt;_shellSettings&lt;/code&gt;, which it got as a constructor dependency). If there&amp;#8217;s no match, it returns null which tells ASP.NET MVC 3 that this route doesn&amp;#8217;t match this request. There&amp;#8217;s a bit more cleverness in here around making sure that paths can be found based on the location of the module itself, which you can have a glance at in here if you&amp;#8217;re interested!&lt;/p&gt;

&lt;p&gt;For now though, we&amp;#8217;ll content ourselves with knowing how the routes are registered on a per shell basis and then how they behave during a request to the application, based on which shell the request was for.&lt;/p&gt;

&lt;h2 id='model_binders_and_shells'&gt;Model Binders and Shells&lt;/h2&gt;

&lt;p&gt;If we go back to our &lt;code&gt;DefaultOrchardHost&lt;/code&gt; the next line after publishing our routes was registering model binders. This is another ASP.NET MVC concept and the way we&amp;#8217;re doing this looks very similar to the way Orchard handled the routes.&lt;/p&gt;

&lt;p&gt;In fact it&amp;#8217;s pretty much exactly the same, meaning we don&amp;#8217;t need to dive in to this too far, except to note one thing &amp;#8212; it isn&amp;#8217;t really implemented! Our &lt;code&gt;ModelBinderPublisher&lt;/code&gt; actually looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;public&lt;/span&gt; &lt;span class='k'&gt;class&lt;/span&gt; &lt;span class='nc'&gt;ModelBinderPublisher&lt;/span&gt; &lt;span class='p'&gt;:&lt;/span&gt; &lt;span class='n'&gt;IModelBinderPublisher&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;private&lt;/span&gt; &lt;span class='k'&gt;readonly&lt;/span&gt; &lt;span class='n'&gt;ModelBinderDictionary&lt;/span&gt; &lt;span class='n'&gt;_binders&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;

    &lt;span class='k'&gt;public&lt;/span&gt; &lt;span class='nf'&gt;ModelBinderPublisher&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;ModelBinderDictionary&lt;/span&gt; &lt;span class='n'&gt;binders&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;_binders&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;binders&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;

    &lt;span class='k'&gt;public&lt;/span&gt; &lt;span class='k'&gt;void&lt;/span&gt; &lt;span class='nf'&gt;Publish&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;IEnumerable&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;ModelBinderDescriptor&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;binders&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='c1'&gt;// MultiTenancy: should hook default model binder instead and rely on shell-specific binders (instead adding to type dictionary)&lt;/span&gt;
        &lt;span class='k'&gt;foreach&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;descriptor&lt;/span&gt; &lt;span class='k'&gt;in&lt;/span&gt; &lt;span class='n'&gt;binders&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
            &lt;span class='n'&gt;_binders&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='n'&gt;descriptor&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Type&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;descriptor&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;ModelBinder&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
        &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, it doesn&amp;#8217;t really deal with multi-tenancy for model binders yet &amp;#8212; Orchard is only at version 1.2xxx after all! In practice it probably isn&amp;#8217;t a problem, but you&amp;#8217;ll know where to look if it is, or when it gets implemented.&lt;/p&gt;

&lt;h2 id='orchard_events'&gt;Orchard Events&lt;/h2&gt;

&lt;p&gt;The last part of the &lt;code&gt;Activate&lt;/code&gt; method in the shell was this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;using&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;events&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_eventsFactory&lt;/span&gt;&lt;span class='p'&gt;())&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;events&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Value&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Activated&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It&amp;#8217;s using &lt;code&gt;_eventsFactory&lt;/code&gt;, which is a function it acquired as a constructor dependency, to get an instance of &lt;code&gt;IOrchardShellEvents&lt;/code&gt;, and calling the &lt;code&gt;Activated&lt;/code&gt; method on it.&lt;/p&gt;

&lt;p&gt;This can be used to signal changes in application status to allow things like background tasks (which will be covered in another article) to take actions at key points in the application lifecycle.&lt;/p&gt;

&lt;h2 id='activation_complete'&gt;Activation Complete!&lt;/h2&gt;

&lt;p&gt;That&amp;#8217;s essentially it for the shell activation. As always I&amp;#8217;d encourage you to go and dive deeper in to the source around the parts I&amp;#8217;ve called out here &amp;#8212; there&amp;#8217;s a lot of interesting code although I&amp;#8217;ve tried to highlight the most relevant parts.&lt;/p&gt;

&lt;p&gt;We&amp;#8217;ve seen how the shell registers routes and binders when it starts up in such a way as to have them only apply to the correct shell. We also saw how the dependency system influences the design of the framework here &amp;#8212; recall how the IoC implementation made it easy for Orchard to get all of the route providers that had been implemented across all relevant modules.&lt;/p&gt;

&lt;p&gt;Hopefully you&amp;#8217;ll come back for the next article, which is going to start to look at the request lifecycle &amp;#8212; now that we&amp;#8217;ve got our application up and running. It&amp;#8217;ll be linked from the &lt;a href='/orchard/2011/08/26/orchard-internals-series.html'&gt;overview&lt;/a&gt; once it&amp;#8217;s ready.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Orchard Host</title>
   <link href="http://xyncro.com/orchard/2011/09/01/orchard-host.html"/>
   <updated>2011-09-01T00:00:00-07:00</updated>
   <id>http://xyncro.com/orchard/2011/09/01/orchard-host</id>
   <content type="html">&lt;p&gt;This is part 2 of a series on &lt;a href='/orchard/2011/08/26/orchard-internals-series.html'&gt;Orchard Internals&lt;/a&gt;. See &lt;a href='/orchard/2011/08/26/orchard-internals-series.html'&gt;the introductory post&lt;/a&gt; for previous posts (and a full post listing).&lt;/p&gt;

&lt;h2 id='overview'&gt;Overview&lt;/h2&gt;

&lt;p&gt;In &lt;a href='/orchard/2011/08/30/orchard-startup-process.html'&gt;part 1&lt;/a&gt; of this series we looked at the startup process in Orchard, as far as obtaining and initializing a host (&lt;code&gt;IOrchardHost&lt;/code&gt;, by default an instance of &lt;code&gt;DefaultOrchardHost&lt;/code&gt;). We saw it get initialized and become a key root point of the application but we didn&amp;#8217;t look inside it and see what&amp;#8217;s happening on initialization. Well &amp;#8212; now we will.&lt;/p&gt;

&lt;h2 id='defaultorchardhost'&gt;DefaultOrchardHost&lt;/h2&gt;

&lt;p&gt;Let&amp;#8217;s go and have a look at &lt;code&gt;DefaultOrchardHost&lt;/code&gt; &amp;#8212; it&amp;#8217;s in the &lt;strong&gt;Orchard.Framework&lt;/strong&gt; project in &lt;strong&gt;Environment/DefaultOrchardHost.cs&lt;/strong&gt;. It&amp;#8217;s a good job Orchard is using IoC to create instances of this &amp;#8212; looking at the constructor it probably wouldn&amp;#8217;t be fun to manage that many dependencies manually!&lt;/p&gt;

&lt;p&gt;We saw that &lt;code&gt;Initialize&lt;/code&gt; gets called as part of the startup process &amp;#8212; that&amp;#8217;s pretty simple, and aside from some logging it just calls &lt;code&gt;BuildCurrent&lt;/code&gt;. That looks a bit more interesting though, like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='n'&gt;IEnumerable&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;ShellContext&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;BuildCurrent&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;_current&lt;/span&gt; &lt;span class='p'&gt;==&lt;/span&gt; &lt;span class='k'&gt;null&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='k'&gt;lock&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;_syncLock&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
            &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;_current&lt;/span&gt; &lt;span class='p'&gt;==&lt;/span&gt; &lt;span class='k'&gt;null&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
                &lt;span class='n'&gt;SetupExtensions&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
                &lt;span class='n'&gt;MonitorExtensions&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
                &lt;span class='n'&gt;_current&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;CreateAndActivate&lt;/span&gt;&lt;span class='p'&gt;().&lt;/span&gt;&lt;span class='n'&gt;ToArray&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
            &lt;span class='p'&gt;}&lt;/span&gt;
        &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;_current&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;#8217;ll ignore the locking as that&amp;#8217;s self-explanatory &amp;#8212; we only want to initialize &lt;code&gt;_current&lt;/code&gt; once regardless of threading. So we&amp;#8217;re left with a couple of calls relating to extensions, and then a call which creates &amp;#8220;some&amp;#8221; &lt;code&gt;ShellContext&lt;/code&gt;s. It looks like there&amp;#8217;s a lot to this &amp;#8212; we&amp;#8217;ll take a look at extensions first.&lt;/p&gt;

&lt;h2 id='extensions'&gt;Extensions&lt;/h2&gt;

&lt;p&gt;Thankfully the naming of the methods in Orchard is generally self-explanatory. &lt;code&gt;SetupExtensions&lt;/code&gt; does what we&amp;#8217;d expect &amp;#8212; it calls a method to setup extensions on &lt;code&gt;_extensionLoaderCoordinator&lt;/code&gt;, one of the dependencies that the host acquired on construction. What does that actually do though? First we&amp;#8217;ll need to look at what implementation of &lt;code&gt;IExtensionLoaderCoordinator&lt;/code&gt; we&amp;#8217;re getting and we can see from a look at our dependency registrations (see &lt;a href='/orchard/2011/08/30/orchard-startup-process.html'&gt;part 1&lt;/a&gt; for where these are) that this is being implemented by &lt;code&gt;ExtensionLoaderCoordinator&lt;/code&gt; which is at &lt;strong&gt;Environment/Extensions/ExtensionLoaderCoordinator.cs&lt;/strong&gt; in the &lt;strong&gt;Orchard.Framework&lt;/strong&gt; project.&lt;/p&gt;

&lt;p&gt;Now we can see that it&amp;#8217;s starting to get a bit more complex! To sum it up, this is where one of the features of Orchard comes in to play, the dynamic compilation, loading and management of extensions &amp;#8212; at runtime. What&amp;#8217;s an extension in this case? Well we&amp;#8217;re probably more used to saying Modules and Themes, but they&amp;#8217;re both a form of extension.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not going to dive in to the details of the extension discovery, compilation and loading mechanisms as part of this article &amp;#8212; it&amp;#8217;s a big enough area that it needs an article all to itself which will be coming later on. For now we&amp;#8217;ll skim over this and say that Orchard is finding any Modules and Themes by looking in some predefined directories and then loading them in to the AppDomain so that they&amp;#8217;re available for Orchard to use. &lt;code&gt;MonitorExtensions&lt;/code&gt; is part of this same process &amp;#8212; it monitors the available extensions on disk (in the previously mentioned directories) and reloads them if they change.&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s simplifying quite a large and complex process, but it&amp;#8217;s enough to give us a feel for what&amp;#8217;s happening at the host level. We can now move on to the last key line of &lt;code&gt;BuildCurrent&lt;/code&gt;, the call to &lt;code&gt;CreateAndActivate&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id='orchard_shells'&gt;Orchard Shells&lt;/h2&gt;

&lt;p&gt;Let&amp;#8217;s start by looking at that &lt;code&gt;CreateAndActivate&lt;/code&gt; method:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='n'&gt;IEnumerable&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;ShellContext&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;CreateAndActivate&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;Logger&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Information&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;Start creation of shells&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

    &lt;span class='n'&gt;IEnumerable&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;ShellContext&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;result&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;allSettings&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_shellSettingsManager&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;LoadSettings&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;allSettings&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Any&lt;/span&gt;&lt;span class='p'&gt;())&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;result&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;allSettings&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Select&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;
        &lt;span class='n'&gt;settings&lt;/span&gt; &lt;span class='p'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
            &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;context&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;CreateShellContext&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
            &lt;span class='n'&gt;ActivateShell&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;context&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
            &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;context&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
        &lt;span class='p'&gt;});&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;else&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
       &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;setupContext&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;CreateSetupContext&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
       &lt;span class='n'&gt;ActivateShell&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;setupContext&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
       &lt;span class='n'&gt;result&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt;&lt;span class='p'&gt;[]&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='n'&gt;setupContext&lt;/span&gt;&lt;span class='p'&gt;};&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;

    &lt;span class='n'&gt;Logger&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Information&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;Done creating shells&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;result&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
		
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;#8217;ll ignore the obvious bits like logging. We start by getting any &lt;code&gt;ShellSettings&lt;/code&gt; instances that the &lt;code&gt;_shellSettingsManager&lt;/code&gt; (an instance of &lt;code&gt;IShellSettingsManager&lt;/code&gt; that came in as a constructor dependency). If we have any instances, we create one ShellContext for each instance, activating each as we go. We then return that list of activated shell contexts. If we didn&amp;#8217;t have any instances of &lt;code&gt;ShellSettings&lt;/code&gt; we just create a new shell context (with some default settings), activate it, and return that (as the only member of an array of shell contexts).&lt;/p&gt;

&lt;p&gt;We&amp;#8217;ll look at what creating a shell entails in a moment but let&amp;#8217;s look first at why sometimes we might have some instances of &lt;code&gt;ShellSettings&lt;/code&gt; and sometimes not. Our instance of &lt;code&gt;IShellSettingsManager&lt;/code&gt; is responsible here, so let&amp;#8217;s see what implementation is being used. Looking at our dependencies it&amp;#8217;s &lt;code&gt;ShellSettingsManager&lt;/code&gt; which can be found in &lt;strong&gt;Environment/Configuration/ShellSettingsManager.cs&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s take a look in there and see why we would (or wouldn&amp;#8217;t) have any shell settings.&lt;/p&gt;

&lt;h2 id='shellsettingsmanager'&gt;ShellSettingsManager&lt;/h2&gt;

&lt;p&gt;We get our shell settings by calling the &lt;code&gt;LoadSettings&lt;/code&gt; method in this class. Let&amp;#8217;s have a look:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='n'&gt;IEnumerable&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;ShellSettings&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;LoadSettings&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;filePaths&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_appDataFolder&lt;/span&gt;
        &lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;ListDirectories&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;Sites&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;SelectMany&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;path&lt;/span&gt; &lt;span class='p'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;_appDataFolder&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;ListFiles&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;path&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt;
        &lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Where&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;path&lt;/span&gt; &lt;span class='p'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='kt'&gt;string&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Equals&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;Path&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;GetFileName&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;path&lt;/span&gt;&lt;span class='p'&gt;),&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Settings.txt&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;StringComparison&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;OrdinalIgnoreCase&lt;/span&gt;&lt;span class='p'&gt;));&lt;/span&gt;

    &lt;span class='k'&gt;foreach&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;filePath&lt;/span&gt; &lt;span class='k'&gt;in&lt;/span&gt; &lt;span class='n'&gt;filePaths&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='k'&gt;yield&lt;/span&gt; &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='nf'&gt;ParseSettings&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;_appDataFolder&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;ReadFile&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;filePath&lt;/span&gt;&lt;span class='p'&gt;));&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;While it uses quite a few Orchard classes to do it, what this method is doing is actually quite straightforward. It&amp;#8217;s finding all of the directories in the &lt;strong&gt;Sites&lt;/strong&gt; directory in our App_Data folder which contain a file called &lt;strong&gt;Settings.txt&lt;/strong&gt;. For each one that it finds, it parses the &lt;strong&gt;Settings.txt&lt;/strong&gt; file in to a &lt;code&gt;ShellSettings&lt;/code&gt; instance and returns it. That&amp;#8217;s pretty straightforward, so in what cases would we end up with differing numbers?&lt;/p&gt;

&lt;p&gt;The first case, where we have no instances of &lt;code&gt;ShellSettings&lt;/code&gt;, is simple. The Orchard installer process has not yet created the default site (a directory called &amp;#8220;Default&amp;#8221; under the &lt;strong&gt;Sites&lt;/strong&gt; directory). Once that&amp;#8217;s been run and the site has gone through the initial setup, you&amp;#8217;ll always have at least one instance of &lt;code&gt;ShellSettings&lt;/code&gt; when this gets called. So we&amp;#8217;d only see no instances of &lt;code&gt;ShellSettings&lt;/code&gt; on our first run (or until we&amp;#8217;ve got a site set up).&lt;/p&gt;

&lt;p&gt;The final case is having &lt;em&gt;more than one&lt;/em&gt; instance. For this to happen we&amp;#8217;d need to have more than one site set up in our &lt;strong&gt;Sites&lt;/strong&gt; directory. Why would we have this? This would be the case if we were running Orchard with multi-tenancy enabled, and we&amp;#8217;d set up multiple tenants for our Orchard site. Each tenant would be another directory in &lt;strong&gt;Sites&lt;/strong&gt; with separate settings. By default Orchard doesn&amp;#8217;t load this module, but it can be turned on like any other if it&amp;#8217;s installed.&lt;/p&gt;

&lt;p&gt;Multi-tenancy is another big topic to cover, and it will get an article all to itself later on, but if you&amp;#8217;re curious now, the &lt;strong&gt;Orchard.MultiTenancy&lt;/strong&gt; project (module) is where the magic happens for this. For now, we&amp;#8217;ll take it as read that we might have multiple shells running, allowing us to run multiple distinct sites within one instance of Orchard.&lt;/p&gt;
&lt;aside&gt;
&lt;p&gt;
A shell has a one to one correspondence with a tenant in Orchard, so if you're running a multi-tenanted site, be aware that things are generally &quot;shell local&quot; &amp;mdash; you won't usually be sharing instances across tenants. If tenants need to talk to each other, you might need to write your own way of doing that! 
&lt;/p&gt;
&lt;/aside&gt;
&lt;p&gt;Now that we&amp;#8217;ve seen where shell settings might come from (and why) let&amp;#8217;s take a look at what happens when shells are created and initialized. Back to our &lt;code&gt;DefaultOrchardHost&lt;/code&gt; implementation&amp;#8230;&lt;/p&gt;

&lt;h2 id='shellcontextfactory'&gt;ShellContextFactory&lt;/h2&gt;

&lt;p&gt;We saw earlier that our shell contexts (instances of &lt;code&gt;ShellContext&lt;/code&gt;) are created by calling either &lt;code&gt;CreateSetupContext&lt;/code&gt; (where we have no shell settings) or &lt;code&gt;CreateShellContext&lt;/code&gt; (where we do have shell settings). Both of these methods make calls to &lt;code&gt;_shellContextFactory&lt;/code&gt;, an instance of &lt;code&gt;IShellContextFactory&lt;/code&gt;, which in this case is implemented by &lt;code&gt;ShellContextFactory&lt;/code&gt;. We call either &lt;code&gt;CreateSetupContext&lt;/code&gt; or &lt;code&gt;CreateShellContext&lt;/code&gt; on that instance, depending on whether or not we have settings (or if the settings we have say they haven&amp;#8217;t been initialized yet).&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s go and take a look in &lt;code&gt;ShellContextFactory&lt;/code&gt;, which can be found in &lt;strong&gt;Environment/ShellBuilders/ShellContextFactory.cs&lt;/strong&gt;. It&amp;#8217;s worth looking at what happens in here as it&amp;#8217;s key to allowing Orchard to work the way it does with regard to IoC, and understanding that can save avoid confusion and problems down the line, especially when working with multiple tenants.&lt;/p&gt;

&lt;p&gt;We&amp;#8217;ll take our usual stance of ignoring logging and that kind of thing, but we&amp;#8217;ll compare the two methods that are called, &lt;code&gt;CreateShellContext&lt;/code&gt; and &lt;code&gt;CreateSetupContext&lt;/code&gt;. Let&amp;#8217;s look at the start of both.&lt;/p&gt;

&lt;p&gt;First &lt;code&gt;CreateShellContext&lt;/code&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='n'&gt;Logger&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Debug&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;Creating shell context for tenant {0}&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Name&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;knownDescriptor&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_shellDescriptorCache&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Fetch&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Name&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;knownDescriptor&lt;/span&gt; &lt;span class='p'&gt;==&lt;/span&gt; &lt;span class='k'&gt;null&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;Logger&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Information&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;No descriptor cached. Starting with minimum components.&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='n'&gt;knownDescriptor&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;MinimumShellDescriptor&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;and &lt;code&gt;CreateSetupContext&lt;/code&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='n'&gt;Logger&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Warning&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;No shell settings available. Creating shell context for setup&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;descriptor&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='n'&gt;ShellDescriptor&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;SerialNumber&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='p'&gt;-&lt;/span&gt;&lt;span class='m'&gt;1&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='n'&gt;Features&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt;&lt;span class='p'&gt;[]&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='n'&gt;ShellFeature&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='n'&gt;Name&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Orchard.Setup&amp;quot;&lt;/span&gt; &lt;span class='p'&gt;},&lt;/span&gt;
        &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='n'&gt;ShellFeature&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='n'&gt;Name&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Shapes&amp;quot;&lt;/span&gt; &lt;span class='p'&gt;},&lt;/span&gt;
        &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='n'&gt;ShellFeature&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt; &lt;span class='n'&gt;Name&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Orchard.jQuery&amp;quot;&lt;/span&gt; &lt;span class='p'&gt;},&lt;/span&gt;
    &lt;span class='p'&gt;},&lt;/span&gt;
&lt;span class='p'&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The obvious point here is that in a setup context we&amp;#8217;re creating a new descriptor for the shell we&amp;#8217;re creating, with only the features (modules) required to run the setup process, and to create a tenant for future use. Where we already have a tenant set up, we expect that we can get a shell descriptor from our cache, but if not we create one which is the minimum required at this stage. (At this point it&amp;#8217;s worth noting that a shell descriptor is basically a list of some metadata about a shell/tenant, such as the name, a unique identifier, and a list of features which should be enabled when available).&lt;/p&gt;

&lt;p&gt;Once we&amp;#8217;ve got a shell descriptor, let&amp;#8217;s see what happens to it:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;blueprint&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_compositionStrategy&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Compose&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;descriptor&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;shellScope&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_shellContainerFactory&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;CreateContainer&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;blueprint&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Those lines are the same in both methods (except for the name of the descriptor instance which is passed in &amp;#8212; these lines were taken from &lt;code&gt;CreateSetupContext&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Now we&amp;#8217;re getting to the critical part of the shell architecture. First of all, we create a &lt;code&gt;ShellBlueprint&lt;/code&gt;, by calling &lt;code&gt;Compose&lt;/code&gt; on our &lt;code&gt;_compositionStrategy&lt;/code&gt; instance, passing in our settings and the descriptor that we&amp;#8217;ve just created or acquired. What is that actually creating at this point? To find out, we&amp;#8217;ll have a quick glance in to &lt;strong&gt;Environment/ShellBuilders/CompositionStrategy.cs&lt;/strong&gt; which is where we find &lt;code&gt;CompositionStrategy&lt;/code&gt;, the implementation of &lt;code&gt;ICompositionStrategy&lt;/code&gt; in use here.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Compose&lt;/code&gt; method looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;public&lt;/span&gt; &lt;span class='n'&gt;ShellBlueprint&lt;/span&gt; &lt;span class='nf'&gt;Compose&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;ShellSettings&lt;/span&gt; &lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;ShellDescriptor&lt;/span&gt; &lt;span class='n'&gt;descriptor&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;Logger&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Debug&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;Composing blueprint&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;enabledFeatures&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_extensionManager&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;EnabledFeatures&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;descriptor&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;features&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_extensionManager&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;LoadFeatures&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;enabledFeatures&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;descriptor&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Features&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Any&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;feature&lt;/span&gt; &lt;span class='p'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;feature&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Name&lt;/span&gt; &lt;span class='p'&gt;==&lt;/span&gt; &lt;span class='s'&gt;&amp;quot;Orchard.Framework&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt;
        &lt;span class='n'&gt;features&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;features&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Concat&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;BuiltinFeatures&lt;/span&gt;&lt;span class='p'&gt;());&lt;/span&gt;

    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;modules&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;BuildBlueprint&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;features&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;IsModule&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;BuildModule&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;dependencies&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;BuildBlueprint&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;features&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;IsDependency&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;BuildDependency&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;descriptor&lt;/span&gt;&lt;span class='p'&gt;));&lt;/span&gt;
    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;controllers&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;BuildBlueprint&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;features&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;IsController&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;BuildController&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;records&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;BuildBlueprint&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;features&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;IsRecord&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;BuildRecord&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;t&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;f&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;));&lt;/span&gt;

    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;result&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='n'&gt;ShellBlueprint&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;Settings&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='n'&gt;Descriptor&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;descriptor&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='n'&gt;Dependencies&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;dependencies&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Concat&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;modules&lt;/span&gt;&lt;span class='p'&gt;).&lt;/span&gt;&lt;span class='n'&gt;ToArray&lt;/span&gt;&lt;span class='p'&gt;(),&lt;/span&gt;
        &lt;span class='n'&gt;Controllers&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;controllers&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
        &lt;span class='n'&gt;Records&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;records&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='p'&gt;};&lt;/span&gt;

    &lt;span class='n'&gt;Logger&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Debug&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;Done composing blueprint&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;result&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This looks a little bit daunting at first glance &amp;#8212; the &lt;code&gt;BuildBlueprint&lt;/code&gt; method throwing generics and &lt;code&gt;Func&amp;lt;...&amp;gt;&lt;/code&gt; around all over the place but it isn&amp;#8217;t as complicated as it seems. In fact almost everything here is about working out what dependencies need to be registered with our IoC container so that the shell can provide any dependencies as they&amp;#8217;re needed &amp;#8212; for the right tenant and with the right &lt;em&gt;scope&lt;/em&gt;. First of all there&amp;#8217;s some checking to see which features in our descriptor are actually available through the extension manager (and recording the ones that are). Next we make sure that if &lt;strong&gt;Orchard.Framework&lt;/strong&gt; is required, all of the built in features from that project are recorded as being required too.&lt;/p&gt;

&lt;p&gt;Once that&amp;#8217;s done, we start to call &lt;code&gt;BuildBlueprint&lt;/code&gt;. While it&amp;#8217;s called with various arguments and functions, it&amp;#8217;s always doing roughly the same thing &amp;#8212; building up a specification of what dependencies need to be registered for this shell. It does this through assembly scanning for certain types, with specific bits of logic for the varying things that might need to be registered (checking for a valid controller, a valid dependency). Once that&amp;#8217;s done we end up with an aggregation of all of the types of dependencies that this shell is going to need, based on the features that have been described.&lt;/p&gt;

&lt;p&gt;This is now what we need to actually build our shell scope through the call we saw earlier to &lt;code&gt;_shellContainerFactory.CreateContainer&lt;/code&gt;.&lt;/p&gt;
&lt;aside&gt;
&lt;p&gt;
At this point it's probably a good idea to make sure you're familiar with the concepts of Lifetime/Scope in Autofac if you want this to make good sense. It's not trivial but it is rather well defined and Nick Blumhardt has an excellent article laying it all out: &lt;a href='http://nblumhardt.com/2011/01/an-autofac-lifetime-primer/'&gt;An Autofac Lifetime Primer&lt;/a&gt;. It's worth reading that if you really want to understand Orchard Internals &amp;mdash; Orchard is using Autofac directly in this area.
&lt;/p&gt;
&lt;/aside&gt;
&lt;p&gt;That call to &lt;code&gt;CreateContainer&lt;/code&gt; gives us an Autofac &lt;code&gt;ILifetimeScope&lt;/code&gt; back, and that becomes a crucial part of our shell context. It means that pretty much anything the tenant needs to resolve (including the shell itself as we create a new &lt;code&gt;ShellContext&lt;/code&gt; instance) will be resolved at the level of the shell lifetime scope, giving segregation and the possibility of very different configurations and loaded features between tenants.&lt;/p&gt;

&lt;h2 id='shellcontainerfactory'&gt;ShellContainerFactory&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;ShellContainerFactory&lt;/code&gt; class (&lt;strong&gt;Environment/ShellBuilders/ShellContainerFactory.cs&lt;/strong&gt;) is the implementation used to build our &lt;code&gt;ILifetimeScope&lt;/code&gt; from our shell settings and shell blueprint. It&amp;#8217;s worth a read through but I&amp;#8217;m not going to go through it all here &amp;#8212; there&amp;#8217;s quite a lot of code, most of which will be quickly readable if you&amp;#8217;re familiar with Autofac. It is worth pulling out one part though, which is where we see how Orchard lets you implement your own dependencies with modules (and control their lifetimes).&lt;/p&gt;

&lt;p&gt;This code (around line 66 onwards) is &lt;strong&gt;important&lt;/strong&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;foreach&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;interfaceType&lt;/span&gt; &lt;span class='k'&gt;in&lt;/span&gt; &lt;span class='n'&gt;item&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Type&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;GetInterfaces&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;
    &lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Where&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;itf&lt;/span&gt; &lt;span class='p'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='k'&gt;typeof&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;IDependency&lt;/span&gt;&lt;span class='p'&gt;).&lt;/span&gt;&lt;span class='n'&gt;IsAssignableFrom&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;itf&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; 
               &lt;span class='p'&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class='p'&gt;!&lt;/span&gt;&lt;span class='k'&gt;typeof&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;IEventHandler&lt;/span&gt;&lt;span class='p'&gt;).&lt;/span&gt;&lt;span class='n'&gt;IsAssignableFrom&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;itf&lt;/span&gt;&lt;span class='p'&gt;)))&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;registration&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;registration&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;As&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;interfaceType&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='k'&gt;typeof&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;ISingletonDependency&lt;/span&gt;&lt;span class='p'&gt;).&lt;/span&gt;&lt;span class='n'&gt;IsAssignableFrom&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;interfaceType&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;registration&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;registration&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;InstancePerMatchingLifetimeScope&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;shell&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt; 
    &lt;span class='k'&gt;else&lt;/span&gt; &lt;span class='nf'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='k'&gt;typeof&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;IUnitOfWorkDependency&lt;/span&gt;&lt;span class='p'&gt;).&lt;/span&gt;&lt;span class='n'&gt;IsAssignableFrom&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;interfaceType&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;registration&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;registration&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;InstancePerMatchingLifetimeScope&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;work&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;else&lt;/span&gt; &lt;span class='nf'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='k'&gt;typeof&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;ITransientDependency&lt;/span&gt;&lt;span class='p'&gt;).&lt;/span&gt;&lt;span class='n'&gt;IsAssignableFrom&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;interfaceType&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
        &lt;span class='n'&gt;registration&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;registration&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;InstancePerDependency&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
    &lt;span class='p'&gt;}&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is where Orchard is looking for the interfaces you would implement when creating your own module containing dependencies that you wish to make available through IoC. We can see clearly here how making our interfaces inherit &lt;code&gt;IDependency&lt;/code&gt;, or &lt;code&gt;ISingletonDependency&lt;/code&gt; will impact the registration of the type you provide within the scope of the shell. It&amp;#8217;s also useful to remember for the future &amp;#8212; if you need to one day extend the Orchard core to deal with more complex registrations and scope within the IoC container this would be the place to start (although it&amp;#8217;s unlikely that&amp;#8217;s going to be needed for most people!)&lt;/p&gt;
&lt;aside&gt;
&lt;p&gt;
&lt;strong&gt;Note&lt;/strong&gt;: It's required that your own interfaces implement (extend) one of the &lt;code&gt;IDependency&lt;/code&gt; interfaces. A class which implements a custom interface and also one of the &lt;code&gt;IDependency&lt;/code&gt; interfaces will not be registered correctly &amp;mdash; the custom interface must extend one of the &lt;code&gt;IDependency&lt;/code&gt; interfaces. This so Orchard knows to register &lt;strong&gt;your custom interface&lt;/strong&gt; and not the base &lt;code&gt;IDependency&lt;/code&gt; interface.
&lt;/p&gt;
&lt;/aside&gt;&lt;aside&gt;
&lt;p&gt;
&lt;strong&gt;Note&lt;/strong&gt;: if you're used to Autofac you'll be used to the default scope of a registration being &lt;code&gt;InstancePerDependency&lt;/code&gt;, so you might assume that this is what you'd get if you implemented &lt;code&gt;IDependency&lt;/code&gt; in Orchard. It's not though &amp;mdash; the default in Orchard is a LifetimeScope which is the scope of a Request. To get the normal Autofac behaviour of an instance per dependency you should implement &lt;code&gt;ITransientDependency&lt;/code&gt;.
&lt;/p&gt;
&lt;/aside&gt;
&lt;p&gt;We can now go back to our &lt;code&gt;ShellContextFactory&lt;/code&gt;. When we&amp;#8217;re creating a setup context, we&amp;#8217;re basically done now. The last part of that method looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='n'&gt;ShellContext&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;Settings&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='n'&gt;Descriptor&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;descriptor&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='n'&gt;Blueprint&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;blueprint&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='n'&gt;LifetimeScope&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;shellScope&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;
    &lt;span class='n'&gt;Shell&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;shellScope&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Resolve&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;IOrchardShell&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;(),&lt;/span&gt;
&lt;span class='p'&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can see that we&amp;#8217;re storing our scope in there, and we&amp;#8217;re also creating our actual shell instance by resolving an &lt;code&gt;IOrchardShell&lt;/code&gt; &amp;#8212; and importantly we&amp;#8217;re doing that in our newly created scope, meaning that we&amp;#8217;ve got just the right registrations and setup for our tenant, isolated from other tenants and their own shells.&lt;/p&gt;

&lt;p&gt;We can finish up looking at shell and shell context creation now by just tying up a loose end &amp;#8212; the other difference between a setup context and a normal shell context. The following code appears in &lt;code&gt;CreateShellContext&lt;/code&gt; before we return a newly created &lt;code&gt;ShellContext&lt;/code&gt; with our shell scope:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='n'&gt;ShellDescriptor&lt;/span&gt; &lt;span class='n'&gt;currentDescriptor&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
&lt;span class='k'&gt;using&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;standaloneEnvironment&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;shellScope&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;CreateWorkContextScope&lt;/span&gt;&lt;span class='p'&gt;())&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;shellDescriptorManager&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;standaloneEnvironment&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Resolve&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;IShellDescriptorManager&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;();&lt;/span&gt;
    &lt;span class='n'&gt;currentDescriptor&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;shellDescriptorManager&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;GetShellDescriptor&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;

&lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;currentDescriptor&lt;/span&gt; &lt;span class='p'&gt;!=&lt;/span&gt; &lt;span class='k'&gt;null&lt;/span&gt; &lt;span class='p'&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class='n'&gt;knownDescriptor&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;SerialNumber&lt;/span&gt; &lt;span class='p'&gt;!=&lt;/span&gt; &lt;span class='n'&gt;currentDescriptor&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;SerialNumber&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;Logger&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Information&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;Newer descriptor obtained. Rebuilding shell container.&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

    &lt;span class='n'&gt;_shellDescriptorCache&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Store&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Name&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;currentDescriptor&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='n'&gt;blueprint&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_compositionStrategy&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Compose&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;currentDescriptor&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='n'&gt;shellScope&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_shellContainerFactory&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;CreateContainer&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;settings&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;blueprint&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;At this point we check if there&amp;#8217;s actually a more up to date shell descriptor already in the environment. If there is, we recompose our blueprint and construct a new shell scope to use rather than the one we created with our cached shell descriptor (as well as sticking the descriptor back in the cache so it&amp;#8217;s there for next time).&lt;/p&gt;

&lt;p&gt;From then on, we&amp;#8217;re back to just returning our newly created shell context, with a shell resolved from the new shell scope.&lt;/p&gt;

&lt;h2 id='defaultorchardhost'&gt;DefaultOrchardHost&lt;/h2&gt;

&lt;p&gt;Finally (this has been a rather long article) we can take ourselves back to our &lt;code&gt;DefaultOrchardHost&lt;/code&gt;, and see that the only really important thing that happens now is our call to &lt;code&gt;ActivateShell&lt;/code&gt;. That looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;private&lt;/span&gt; &lt;span class='k'&gt;void&lt;/span&gt; &lt;span class='nf'&gt;ActivateShell&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;ShellContext&lt;/span&gt; &lt;span class='n'&gt;context&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;context&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Shell&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Activate&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
    &lt;span class='n'&gt;_runningShellTable&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Add&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;context&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Settings&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can see that we&amp;#8217;re actually calling &lt;code&gt;Activate&lt;/code&gt; on our instance of &lt;code&gt;IOrchardShell&lt;/code&gt;, before registering that shell in our table of running shells.&lt;/p&gt;

&lt;p&gt;While we could start to dive in to what activating a shell means, that&amp;#8217;s best served with a separate article &amp;#8212; this one is more than long enough. So let&amp;#8217;s wrap that up there. We&amp;#8217;ve seen how shells and shell contexts get created based on the site/tenant settings in our &lt;strong&gt;App_Data/Sites&lt;/strong&gt; directory, and we&amp;#8217;ve seen how the settings there go towards making up an IoC scope for the shell and context.&lt;/p&gt;

&lt;p&gt;We&amp;#8217;ve also seen how the dependencies we create in our own custom modules get registered with the underlying shell and scope, so we know what we can do by default with Orchard for dependency specification.&lt;/p&gt;

&lt;p&gt;Next up we&amp;#8217;ll look at activating the shell, so check back to the &lt;a href='/orchard/2011/08/26/orchard-internals-series.html'&gt;main introductory post and the list of articles&lt;/a&gt; to see when that gets posted (or subscribe to the &lt;a href='/atom.xml'&gt;Atom feed&lt;/a&gt; if that&amp;#8217;s you&amp;#8217;re thing).&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Orchard Startup</title>
   <link href="http://xyncro.com/orchard/2011/08/30/orchard-startup-process.html"/>
   <updated>2011-08-30T00:00:00-07:00</updated>
   <id>http://xyncro.com/orchard/2011/08/30/orchard-startup-process</id>
   <content type="html">&lt;p&gt;This is part 1 of a series on &lt;a href='/orchard/2011/08/26/orchard-internals-series.html'&gt;Orchard Internals&lt;/a&gt;. Other posts will be linked from &lt;a href='/orchard/2011/08/26/orchard-internals-series.html'&gt;the introduction&lt;/a&gt; as they are published.&lt;/p&gt;

&lt;h2 id='overview'&gt;Overview&lt;/h2&gt;

&lt;p&gt;Orchard does a lot when it starts up. Although it&amp;#8217;s an ASP.NET MVC 3 web application at heart, it replaces/augments/ignores various things as it needs to. This article will follow through the application startup process and see what gets run at this stage, right up until Orchard is ready to serve the first actual request.&lt;/p&gt;

&lt;h2 id='the_web_application'&gt;The Web Application&lt;/h2&gt;

&lt;p&gt;Everything starts off in the web application itself. If you&amp;#8217;ve got the &lt;a href='http://orchard.codeplex.com/releases/'&gt;source code&lt;/a&gt; handy (and these articles will make much more sense if you have), this is the &lt;strong&gt;Orchard.Web&lt;/strong&gt; project. Looking in here we see&amp;#8230; not a lot. This is because Orchard only really uses this as a boot up point for the application proper. There&amp;#8217;s no content in here or traditional models, controllers and views &amp;#8212; only the code needed to call out to Orchard and get things running.&lt;/p&gt;

&lt;p&gt;If we look in the &lt;strong&gt;global.asax.cs&lt;/strong&gt; file of the Orchard.Web project, this is where we&amp;#8217;ll find our Orchard code. We don&amp;#8217;t have some of the code which would normally be present in a default ASP.NET MVC 3 web app &amp;#8212; there&amp;#8217;s no registration of Areas or Filters in here as Orchard deals with these itself. It doesn&amp;#8217;t map any Routes either, only ignoring the Route for resource.axd, as Orchard deals with Routes too.&lt;/p&gt;

&lt;p&gt;The first place to look is in the application start method, which looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;protected&lt;/span&gt; &lt;span class='k'&gt;void&lt;/span&gt; &lt;span class='nf'&gt;Application_Start&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;RegisterRoutes&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;RouteTable&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Routes&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='n'&gt;_starter&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='n'&gt;Starter&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;IOrchardHost&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;(&lt;/span&gt;&lt;span class='n'&gt;HostInitialization&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;HostBeginRequest&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;HostEndRequest&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='n'&gt;_starter&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;OnApplicationStart&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='k'&gt;this&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The call to &lt;code&gt;RegisterRoutes&lt;/code&gt; is normal, but then we&amp;#8217;re straight in to Orchard code. We create a new &lt;code&gt;Starter&amp;lt;IOrchardHost&amp;gt;&lt;/code&gt; and assign it to &lt;code&gt;_starter&lt;/code&gt;, which is a static member of the application so it&amp;#8217;s always available.&lt;/p&gt;

&lt;p&gt;This gets passed a few arguments on construction, each of which is a method to call at different application stages &amp;#8212; on start, beginning a request, and ending a request. The one which really matters to us here is the method which is going to get called on application start &amp;#8212; and which is actually invoked as part of calling &lt;code&gt;OnApplicationStart&lt;/code&gt; on our instance of &lt;code&gt;Starter&amp;lt;IOrchardHost&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id='orchardwarmupstarter'&gt;Orchard.WarmupStarter&lt;/h2&gt;

&lt;p&gt;We&amp;#8217;ve seen that we&amp;#8217;re creating a new &lt;code&gt;Starter&amp;lt;IOrchardHost&amp;gt;&lt;/code&gt; here, so let&amp;#8217;s have a look at that. This class can be found in the &lt;strong&gt;Orchard.WarmupStarter&lt;/strong&gt; project, which is the only Orchard project which is explicitly referenced in the web application - it&amp;#8217;s referenced in the &lt;strong&gt;web.config&lt;/strong&gt; file. This is because &lt;strong&gt;Orchard.WarmupStarter&lt;/strong&gt; also provides an HttpModule (which is a bit out of scope in this article, but will likely be mentioned elsewhere at some point).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Starter&amp;lt;T&amp;gt;&lt;/code&gt; (&lt;strong&gt;Starter.cs&lt;/strong&gt;) is where we want to look. We&amp;#8217;ve seen that we&amp;#8217;re passing it three methods which it can call (with suitable signatures) and when we construct it it simply stores those as member variables. When we then call &lt;code&gt;OnApplicationStart&lt;/code&gt; it calls &lt;code&gt;LaunchStartupThread&lt;/code&gt;, passing the HttpApplication instance that we&amp;#8217;ve just given it. &lt;code&gt;LaunchStartupThread&lt;/code&gt; looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;public&lt;/span&gt; &lt;span class='k'&gt;void&lt;/span&gt; &lt;span class='nf'&gt;LaunchStartupThread&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;HttpApplication&lt;/span&gt; &lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='c1'&gt;// Make sure incoming requests are queued&lt;/span&gt;
    &lt;span class='n'&gt;WarmupHttpModule&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;SignalWarmupStart&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;

    &lt;span class='n'&gt;ThreadPool&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;QueueUserWorkItem&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;
        &lt;span class='n'&gt;state&lt;/span&gt; &lt;span class='p'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
            &lt;span class='k'&gt;try&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
                &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;result&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;_initialization&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
                &lt;span class='n'&gt;_initializationResult&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;result&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
            &lt;span class='p'&gt;}&lt;/span&gt;
            &lt;span class='k'&gt;catch&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;Exception&lt;/span&gt; &lt;span class='n'&gt;e&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
                &lt;span class='k'&gt;lock&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;_synLock&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
                &lt;span class='n'&gt;_error&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;e&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
                &lt;span class='n'&gt;_previousError&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='k'&gt;null&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
            &lt;span class='p'&gt;}&lt;/span&gt;
        &lt;span class='p'&gt;}&lt;/span&gt;
        &lt;span class='k'&gt;finally&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
            &lt;span class='c1'&gt;// Execute pending requests as the initialization is over&lt;/span&gt;
            &lt;span class='n'&gt;WarmupHttpModule&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;SignalWarmupDone&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
        &lt;span class='p'&gt;}&lt;/span&gt;
    &lt;span class='p'&gt;});&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Most of this is just concerned with making sure that this is run asynchronously (and working with the previously mentioned module) and that any errors which result are caught and recorded/dealt with properly, but the key part is that we&amp;#8217;re initializing &lt;code&gt;_initializationResult&lt;/code&gt; to the result of the method we passed in on construction. This is our generic type, which we&amp;#8217;ve seen is of type &lt;code&gt;IOrchardHost&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is important - this is the host that&amp;#8217;s going to be the root of our Orchard application &amp;#8212; anything that happens in Orchard is going to happen as a result of calls in to this root object and the objects it will create and maintain. It&amp;#8217;s stored in the &lt;code&gt;Starter&amp;lt;T&amp;gt;&lt;/code&gt; which in turn is a static member of our web application, so the lifetime for this root object is the same as the application itself.&lt;/p&gt;

&lt;p&gt;So &amp;#8212; what&amp;#8217;s the root object? We need to pop back to our &lt;strong&gt;global.asax.cs&lt;/strong&gt; and see what the method which constructs our root object gives us.&lt;/p&gt;

&lt;h2 id='orchardstarter'&gt;OrchardStarter&lt;/h2&gt;

&lt;p&gt;The method that gets called to create our host object is &lt;code&gt;HostInitialization&lt;/code&gt; in &lt;strong&gt;global.asax.cs&lt;/strong&gt;. That looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;private&lt;/span&gt; &lt;span class='k'&gt;static&lt;/span&gt; &lt;span class='n'&gt;IOrchardHost&lt;/span&gt; &lt;span class='nf'&gt;HostInitialization&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;HttpApplication&lt;/span&gt; &lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;host&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;OrchardStarter&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;CreateHost&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;MvcSingletons&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

    &lt;span class='n'&gt;host&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Initialize&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;

    &lt;span class='c1'&gt;// initialize shells to speed up the first dynamic query&lt;/span&gt;
    &lt;span class='n'&gt;host&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;BeginRequest&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
    &lt;span class='n'&gt;host&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;EndRequest&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;

    &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;host&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;#8217;re getting our &lt;code&gt;IOrchardHost&lt;/code&gt; instance by calling &lt;code&gt;OrchardStarter.CreateHost&lt;/code&gt;. This is where the meat of our object instantiation is going to happen. It&amp;#8217;s also the first place that we see another key element of Orchard, the use of &lt;em&gt;IoC&lt;/em&gt;.&lt;/p&gt;
&lt;aside&gt;&lt;p&gt;
&lt;strong&gt;Note&lt;/strong&gt;: If you're not familiar with IoC that's a pretty big topic in its own right, and I'm not about to go in to a lengthy discussion of that &amp;mdash; these articles are plenty long enough on their own. Martin Fowler has written a solid and detailed explanation of the principles of &lt;a href='http://martinfowler.com/articles/injection.html'&gt;Dependency Injection&lt;/a&gt; which covers IoC, and the &lt;a href='http://code.google.com/p/autofac/wiki/GettingStarted'&gt;Autofac Wiki&lt;/a&gt; has plenty of information about IoC and Autofac (the IoC container which Orchard uses under the hood). It'll probably help to understand IoC when working with Orchard.
&lt;/p&gt;&lt;/aside&gt;
&lt;p&gt;Let&amp;#8217;s look at &lt;code&gt;OrchardStarter&lt;/code&gt; and see what it&amp;#8217;s doing. It&amp;#8217;s in the &lt;strong&gt;Orchard.Framework&lt;/strong&gt; project in &lt;strong&gt;Environment/OrchardStarter.cs&lt;/strong&gt;. We start off by calling &lt;code&gt;CreateHost&lt;/code&gt;, passing in an Action which takes a &lt;code&gt;ContainerBuilder&lt;/code&gt;. This is an Autofac concept, but essentially it&amp;#8217;s the class used to register dependencies when we build an IoC container. At the moment it&amp;#8217;s being passed a method &lt;code&gt;MvcSingletons&lt;/code&gt; in our &lt;strong&gt;global.asax.cs&lt;/strong&gt; which registers the Routes, Binders and View Engines as they are currently set up for the application, making them available to the IoC container.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CreateHost&lt;/code&gt; looks like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;public&lt;/span&gt; &lt;span class='k'&gt;static&lt;/span&gt; &lt;span class='n'&gt;IOrchardHost&lt;/span&gt; &lt;span class='nf'&gt;CreateHost&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;Action&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;ContainerBuilder&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;registrations&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;container&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;CreateHostContainer&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;registrations&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
    &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;container&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Resolve&lt;/span&gt;&lt;span class='p'&gt;&amp;lt;&lt;/span&gt;&lt;span class='n'&gt;IOrchardHost&lt;/span&gt;&lt;span class='p'&gt;&amp;gt;();&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It gets an IoC container by calling &lt;code&gt;CreateHostContainer&lt;/code&gt; and then asks that container for an instance of &lt;code&gt;IOrchardHost&lt;/code&gt;. &lt;code&gt;CreateHostContainer&lt;/code&gt; (which I won&amp;#8217;t give source for here, but it&amp;#8217;s a very useful place to look if you&amp;#8217;re wondering what implentation of an interface is used by default) registers all of the default dependencies that Orchard needs to run &amp;#8212; all of the dependencies needed to create an &lt;code&gt;IOrchardHost&lt;/code&gt;. So we can see that IoC is key to Orchard &amp;#8212; there&amp;#8217;s no manual creation of object graphs here, just IoC being used to satisfy all of the dependencies at runtime.&lt;/p&gt;

&lt;p&gt;This is also a really useful place to look if you&amp;#8217;re wondering about the lifecycle of any of the components of Orchard. It&amp;#8217;s likely that they&amp;#8217;re registered here, with the lifecycle being managed by the IoC container (Autofac is very good in this regard).&lt;/p&gt;

&lt;h2 id='defaultorchardhost'&gt;DefaultOrchardHost&lt;/h2&gt;

&lt;p&gt;At this point, if all has gone well, we have an instance of &lt;code&gt;IOrchardHost&lt;/code&gt;. Looking at &lt;code&gt;CreateHostContainer&lt;/code&gt; we can see that this will actually be an instance of &lt;code&gt;DefaultOrchardHost&lt;/code&gt; &amp;#8212; that&amp;#8217;s the type which has been registered for this interface. Now we can go back to our web application in &lt;strong&gt;global.asax.cs&lt;/strong&gt; and wrap up the tour of the startup process by looking what happens to our host.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='csharp'&gt;&lt;span class='k'&gt;private&lt;/span&gt; &lt;span class='k'&gt;static&lt;/span&gt; &lt;span class='n'&gt;IOrchardHost&lt;/span&gt; &lt;span class='nf'&gt;HostInitialization&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;HttpApplication&lt;/span&gt; &lt;span class='n'&gt;application&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;host&lt;/span&gt; &lt;span class='p'&gt;=&lt;/span&gt; &lt;span class='n'&gt;OrchardStarter&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;CreateHost&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;MvcSingletons&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;

    &lt;span class='n'&gt;host&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;Initialize&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;

    &lt;span class='c1'&gt;// initialize shells to speed up the first dynamic query&lt;/span&gt;
    &lt;span class='n'&gt;host&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;BeginRequest&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
    &lt;span class='n'&gt;host&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;EndRequest&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;

    &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;host&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Looking again at our host initialization code, we can see that we call &lt;code&gt;Initialize&lt;/code&gt; on our host. That&amp;#8217;s pretty much it &amp;#8212; the other calls on our host here are just there for performance reasons and aren&amp;#8217;t really relevant to our startup process.&lt;/p&gt;

&lt;h2 id='wrapping_up'&gt;Wrapping Up&lt;/h2&gt;

&lt;p&gt;So we&amp;#8217;ve been through the startup procedure and seen how Orchard creates the runtime environment. We haven&amp;#8217;t looked at the actual host much yet &amp;#8212; we&amp;#8217;ll look at that in the next article in this series, but we have seen how a host is constructed so we can probably have a guess that by now our host has all of the dependencies it needs and is ready to start handling Orchard requests.&lt;/p&gt;

&lt;p&gt;We&amp;#8217;ve also seen where to find the default registrations and lifecycles for the core Orchard components and how those are made available to the host.&lt;/p&gt;

&lt;p&gt;We&amp;#8217;re now ready to start taking a deep dive in to the &lt;a href='/orchard/2011/09/01/orchard-host.html'&gt;Orchard Host&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Orchard Internals</title>
   <link href="http://xyncro.com/orchard/2011/08/26/orchard-internals-series.html"/>
   <updated>2011-08-26T00:00:00-07:00</updated>
   <id>http://xyncro.com/orchard/2011/08/26/orchard-internals-series</id>
   <content type="html">&lt;p&gt;Lately I&amp;#8217;ve been doing quite a bit of work with the &lt;a href='http://www.orchardproject.net'&gt;Orchard CMS&lt;/a&gt;. It&amp;#8217;s a powerful system and although it&amp;#8217;s quite new, becoming a 1.0 at the beginning of this year, there&amp;#8217;s a lot of code to understand if you want to start extending it and working with it in significant ways as a developer.&lt;/p&gt;

&lt;p&gt;While &lt;a href='http://www.orchardproject.net/docs/'&gt;the documentation&lt;/a&gt; is pretty good, I find that it helps me to really understand the internals of a system I&amp;#8217;m using, especially when &amp;#8212; like Orchard &amp;#8212; it does quite a lot based on convention and &amp;#8220;magic&amp;#8221;. So I&amp;#8217;ll be writing a series here which is a crawl around some of the Orchard internals examining how it works and which bits do what. It helps me to understand the system better, and hopefully it&amp;#8217;ll have some value for other developers that want to better understand Orchard and push the limits of what can be done with it.&lt;/p&gt;

&lt;p&gt;I should note now that I&amp;#8217;m not on the Orchard team &amp;#8212; I didn&amp;#8217;t write any of this code, so if I misunderstand it, apologies in advance. I&amp;#8217;ll happily make corrections where errors or inclarity are pointed out.&lt;/p&gt;

&lt;p&gt;Posts will be listed below as they&amp;#8217;re added&amp;#8230;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href='/orchard/2011/08/30/orchard-startup-process.html'&gt;The Orchard Startup Process&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='/orchard/2011/09/01/orchard-host.html'&gt;The Orchard Host&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='/orchard/2011/09/13/orchard-shell-activation.html'&gt;Orchard Shell Activation&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Request Lifecycle in Orchard&lt;/li&gt;

&lt;li&gt;Orchard Extensions Mechanics&lt;/li&gt;

&lt;li&gt;next&amp;#8230;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note that if something says it&amp;#8217;s &amp;#8220;in progress&amp;#8221;, that pretty much means I&amp;#8217;m writing it in public and I haven&amp;#8217;t finished yet. Sometimes it takes me a few days to write things, other times I rattle through in an hour, but I quite like just getting something up even if it&amp;#8217;s not finished. If something stops weirdly half way through, come back and check whether I&amp;#8217;m writing as you&amp;#8217;re reading &amp;#8212; I&amp;#8217;ll finish off soon, just bear with me&amp;#8230;&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;ve got any suggestions for areas you&amp;#8217;d like me to cover, corrections, thoughts, etc. just drop me an email (see the Contact page) or say hello on Twitter, etc.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Hello!</title>
   <link href="http://xyncro.com/2011/08/25/hello.html"/>
   <updated>2011-08-25T00:00:00-07:00</updated>
   <id>http://xyncro.com/2011/08/25/hello</id>
   <content type="html">&lt;p&gt;There&amp;#8217;s not a lot to say in first posts on blogs, and I certainly can&amp;#8217;t think of anything. All I really want to indicate is that I&amp;#8217;ll be blogging on mainly software development and tech related things. A lot of them will probably be .NET because that&amp;#8217;s work related, but I&amp;#8217;m sure I&amp;#8217;ll be writing about some of the other things I enjoy fiddling with as well (Ruby, Erlang, Io, Haskell, compilers, distributed things, you name it).&lt;/p&gt;

&lt;p&gt;Anyway, enough waffle &amp;#8212; time to start writing real content.&lt;/p&gt;</content>
 </entry>
 
</feed>

