public
Description: SharePoint Application Framework
Homepage:
Clone URL: git://github.com/butaji/Sapphire.git
Sapphire / trunk / Sapphire.Application / Application.cs
100644 69 lines (63 sloc) 1.959 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using Sapphire.Web.UI;
 
namespace Sapphire
{
  public class Application : Microsoft.SharePoint.ApplicationRuntime.SPHttpApplication
  {
    private static readonly object LockObject = new object();
    private static IUnityContainer _container;
 
    /// <summary>
    /// Gets and sets the Unity Container
    /// </summary>
    public virtual IUnityContainer Container
    {
      get { return _container; }
      protected set { _container = value; }
    }
 
    /// <summary>
    /// Handles the <see cref="Start"/> event and defines the application lifecycle.
    /// </summary>
    /// <param name="sender">The object firing the event.</param>
    /// <param name="e">The event associated data.</param>
    protected virtual void Application_Start(object sender, EventArgs e)
    {
      CreateContainer();
      AddRequiredServices();
      Start();
    }
 
    /// <summary>
    /// Adds the required application services to the container.
    /// </summary>
    /// <remarks>Override this method to add or change the services available in the container.</remarks>
    protected virtual void AddRequiredServices()
    {
    }
 
    /// <summary>
    /// Creates the application root container.
    /// </summary>
    /// <remarks>Override this method to change the container to be used by the application.</remarks>
    protected virtual void CreateContainer()
    {
      if (Container == null)
      {
        lock (LockObject)
        {
          if (Container == null)
          {
            IUnityContainer container = new UnityContainer();
            Container = container;
            Container.RegisterInstance(Container);
          }
        }
      }
    }
 
    /// <summary>
    /// Override this method to add behavior to be executed once the application has started.
    /// </summary>
    protected virtual void Start()
    {
    }
  }
}