-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobal.asax.cs
More file actions
125 lines (101 loc) · 4.35 KB
/
Global.asax.cs
File metadata and controls
125 lines (101 loc) · 4.35 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System.Web.Optimization;
using NHibernate.Validator.Event;
namespace WebrootUI2.Web.Mvc
{
using System;
using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
using Castle.Windsor;
// WebrootUI2.Web.Mvc.CastleWindsor
using CastleWindsor;
using CommonServiceLocator.WindsorAdapter;
using Controllers;
using Infrastructure.NHibernateMaps;
using SharpArch.Domain.Events;
using Microsoft.Practices.ServiceLocation;
using SharpArch.NHibernate;
using SharpArch.NHibernate.Web.Mvc;
using SharpArch.Web.Mvc.Castle;
using SharpArch.Web.Mvc.ModelBinder;
using WebrootUI2.Web.Mvc.App_Start;
using System.Web.Http;
using System.Web;
using Environment = NHibernate.Validator.Cfg.Environment;
/// <summary>
/// Represents the MVC Application
/// </summary>
/// <remarks>
/// For instructions on enabling IIS6 or IIS7 classic mode,
/// visit http://go.microsoft.com/?LinkId=9394801
/// </remarks>
public class MvcApplication : System.Web.HttpApplication
{
private WebSessionStorage webSessionStorage;
/// <summary>
/// Due to issues on IIS7, the NHibernate initialization must occur in Init().
/// But Init() may be invoked more than once; accordingly, we introduce a thread-safe
/// mechanism to ensure it's only initialized once.
/// See http://msdn.microsoft.com/en-us/magazine/cc188793.aspx for explanation details.
/// </summary>
public override void Init()
{
base.Init();
this.webSessionStorage = new WebSessionStorage(this);
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
NHibernateInitializer.Instance().InitializeNHibernateOnce(this.InitialiseNHibernateSessions);
}
protected void Application_Error(object sender, EventArgs e)
{
// Useful for debugging
Exception ex = this.Server.GetLastError();
var reflectionTypeLoadException = ex as ReflectionTypeLoadException;
}
protected void Application_Start()
{
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
ModelBinders.Binders.DefaultBinder = new SharpModelBinder();
ModelValidatorProviders.Providers.Add(new ClientDataTypeModelValidatorProvider());
InitializeValidator();
this.InitializeServiceLocator();
BundleConfig.RegisterBundles(BundleTable.Bundles);
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
RouteRegistrar.RegisterRoutesTo(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
}
private void InitializeValidator()
{
var provider = new NHibernateSharedEngineProvider();
Environment.SharedEngineProvider = provider;
}
/// <summary>
/// Instantiate the container and add all Controllers that derive from
/// WindsorController to the container. Also associate the Controller
/// with the WindsorContainer ControllerFactory.
/// </summary>
protected virtual void InitializeServiceLocator()
{
IWindsorContainer container = new WindsorContainer();
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
container.RegisterControllers(typeof(BaseController).Assembly);
ComponentRegistrar.AddComponentsTo(container);
var windsorServiceLocator = new WindsorServiceLocator(container);
DomainEvents.ServiceLocator = windsorServiceLocator;
ServiceLocator.SetLocatorProvider(() => windsorServiceLocator);
}
private void InitialiseNHibernateSessions()
{
NHibernateSession.ConfigurationCache = new NHibernateConfigurationFileCache();
NHibernateSession.Init(
this.webSessionStorage,
new[] { Server.MapPath("~/bin/WebrootUI2.Infrastructure.dll") },
new AutoPersistenceModelGenerator().Generate(),
Server.MapPath("~/NHibernate.config"));
}
}
}