The biggest difference between Orchard Framework and class library is that the Framework combines a series of scattered components together to form a whole. Next, Orchard Framework analyzes how Orchard combines related components together, which is the startup process of the Framework.

The Orchard startup process can be viewed in the following file.

  1. Orchard. Web. Global. Asax: This file mainly contains the application level event handling code, generally used for ASP.NET application startup initialization, etc. In Orchard, the Application_Start event is used to initialize the application. The initialization is performed by specifying HostInitialization, HostBeginRequest, and HostEndRequest. And hand it off to Starter).
1 protected void Application_Start() {2 RegisterRoutes(routetable.routes); 3 _starter = new Starter<IOrchardHost>(HostInitialization, HostBeginRequest, HostEndRequest); 4 _starter.OnApplicationStart(this); 5}Copy the code

Note: Autofac is used to define the method of registering routing table information and call IoC container creation in HostInitialization.

1 Private static IOrchardHost Initialization(HttpApplication Application) {2 var host = OrchardStarter.CreateHost(MvcSingletons); 3 4 host.Initialize(); 5 6 // initialize shells to speed up the first dynamic query 7 host.BeginRequest(); 8 host.EndRequest(); 9 10 return host; 11 } 12 13 static void MvcSingletons(ContainerBuilder builder) { 14 builder.Register(ctx => RouteTable.Routes).SingleInstance(); 15 builder.Register(ctx => ModelBinders.Binders).SingleInstance(); 16 builder.Register(ctx => ViewEngines.Engines).SingleInstance(); 17}Copy the code

  

 

2. Orchard. WarmupStarter. Starter. Cs: Starter has three main functions

  • Combined with WarmupHttpModule, blocks requests during startup and processes the request queue after startup.
  • Logs errors that occur during startup, and reinitializes them by listening on request events.
  • Create the IoC container, and this is the most important one. Use HostInitialization as defined in Global.asax to create the entire base container.

 

3. Orchard. Framework. DefaultOrchardHost. Cs: the Host is Orchard launched the entire core, its start mainly has three steps:

  • Load the extension module.
  • Monitor expansion module.
  • Create and activate a Shell(multi-tenant).

 

The code is as follows:

1 IEnumerable<ShellContext> BuildCurrent() { 2 if (_shellContexts == null) { 3 lock (_syncLock) { 4 if (_shellContexts == null) { 5 SetupExtensions(); 6 MonitorExtensions(); 7 CreateAndActivateShells(); 8 } 9 } 10 } 11 return _shellContexts; 12}Copy the code

 

 

Summary:

This chapter analyzes Orchard’s main startup process, which is shown below except WarmupStarter.

 

 

 

This series focuses on what You can learn from Orchard, and I think Orchard’s use of queues to block requests at startup and Orchard’s initialization steps can be learned.