The framework has replaced the standard start process with a bootstrapping mechanism for starting the service. The global.asx should inherit from RestHttpApplication which controls the boot behaviour.
The Global.asax markup page should be edited to show the inherited file. Note you can choose to implement a code behind file or include the file in your own assembly.
<@ Application Codebehind="Global.asax.cs" 
               Inherits="BrettM.SimpleDemo.WebApp.SimpleRestDemoApplication"
               Language="C#" >
Implmentation code of the global.asax.cs file
    public class SimpleRestDemoApplication
                 : RestHttpApplication
    { 
        // Implementation code
    }

Application_Start

When an instance of the web application is crated, the Application_Start method is automatically called.

BootStrappingSequence.png

Application_Start calls the virtual method OnCreateContainer which should be overridden in the global.asax.cs shart.&#160; This methods should be responsible for setting up the unity container, including
  • Registering bootstrappers
  • Data stores
  • Restful Controllers
  • Other custom components

The application_Start method will then create a PropertyBag (discussed below) and then resolve all IBootStrappers from the container.

Each BootStrappers will be loaded and the OnStart Event will be called.&#160; The code within the OnStart should contain any initialisation code.

BootStrappers

The interface a BootStrapper should use to create custom BootStrappers.&#160; This is described below.</p>

using Microsoft.Practices.Unity;

namespace BrettM.Web.Hosting
{
    /// <summary>
    /// 
    /// </summary>
    public interface IBootStrapper
    {
        /// <summary>
        /// This event is triggered when the HttpApplication starts up
        /// </summary>
        /// <param name="container" />An instance of the unity container is passed, 
        /// allowing the bootstrapper to keep values until shutdown</param>
        /// <param name="bag" /></param>
        void OnStart(IUnityContainer container, PropertyBag bag);

        /// <summary>
        /// This event is triggered when the HttpApplication shuts down
        /// </summary>
        /// <param name="container" /></param>
        /// <param name="bag" /></param>
        void OnStop(IUnityContainer container, PropertyBag bag);
    }
}

Once retuned, the Application_Start will create a PropertyBag object which will be passed to each BootStrappers

PropertyBag
A PropertyBag allows a BootStrappers to store information or state in a key/value pair this pair.&#160; This state information can later be retrieved by other BootStrappers or during shutdownAn example is a BootStrappers may wish to restore state.

Last edited May 2, 2010 at 3:40 AM by BrettM, version 2

Comments

No comments yet.