diff --git a/src/Umbraco.Core/ApplicationContext.cs b/src/Umbraco.Core/ApplicationContext.cs index 4f1e449a20..1f39c1b9ee 100644 --- a/src/Umbraco.Core/ApplicationContext.cs +++ b/src/Umbraco.Core/ApplicationContext.cs @@ -12,11 +12,7 @@ namespace Umbraco.Core /// public class ApplicationContext { - - private static ApplicationContext _instance; - private static readonly object Locker = new object(); - - /// + /// /// Constructor /// /// @@ -25,25 +21,12 @@ namespace Umbraco.Core Plugins = pluginResolver; } - /// - /// Singleton accessor - /// - public static ApplicationContext Current - { - get - { - return _instance; - } - set - { - lock (Locker) - { - _instance = value; - } - } - } + /// + /// Singleton accessor + /// + public static ApplicationContext Current { get; set; } - // IsReady is set to true by the boot manager once it has successfully booted + // IsReady is set to true by the boot manager once it has successfully booted // note - the original umbraco module checks on content.Instance in umbraco.dll // now, the boot task that setup the content store ensures that it is ready bool _isReady = false; diff --git a/src/Umbraco.Web.UI/Global.asax b/src/Umbraco.Web.UI/Global.asax new file mode 100644 index 0000000000..1627b363bc --- /dev/null +++ b/src/Umbraco.Web.UI/Global.asax @@ -0,0 +1 @@ +<%@ Application Codebehind="Global.asax.cs" Inherits="Umbraco.Web.UmbracoApplication" Language="C#" %> diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 6f4ac938d7..97a5a03c2b 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -306,6 +306,7 @@ UI.xml + diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 98d3136fef..a9174e4cfb 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -1759,6 +1759,7 @@ + diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs new file mode 100644 index 0000000000..635d873bf5 --- /dev/null +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using Umbraco.Core; + +namespace Umbraco.Web +{ + /// + /// The Umbraco global.asax class + /// + public class UmbracoApplication : System.Web.HttpApplication + { + + private static readonly TraceSource Trace = new TraceSource("UmbracoApplication"); + + /// + /// Initializes the Umbraco application + /// + /// + /// + protected virtual void Application_Start(object sender, EventArgs e) + { + Trace.TraceInformation("Initialize AppDomain"); + + // Backwards compatibility - set the path and URL type for ClientDependency 1.5.1 [LK] + ClientDependency.Core.CompositeFiles.Providers.XmlFileMapper.FileMapVirtualFolder = "~/App_Data/TEMP/ClientDependency"; + ClientDependency.Core.CompositeFiles.Providers.BaseCompositeFileProcessingProvider.UrlTypeDefault = ClientDependency.Core.CompositeFiles.Providers.CompositeUrlType.Base64QueryStrings; + + //create the ApplicationContext + ApplicationContext.Current = new ApplicationContext(new PluginResolver()) + { + IsReady = true // fixme + }; + + Trace.TraceInformation("AppDomain is initialized"); + } + + protected virtual void Application_Error(object sender, EventArgs e) + { + + } + + protected virtual void Application_End(object sender, EventArgs e) + { + + } + } +} diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index fd978332ba..d4b2ba0d35 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -302,7 +302,16 @@ namespace Umbraco.Web // and there may be more than 1 application per application domain public void Init(HttpApplication app) { - InitializeApplication(app); + // used to be done in PostAuthorizeRequest but then it disabled OutputCaching due + // to rewriting happening too early in the chain (Alex Norcliffe 2010-02). + app.PostResolveRequestCache += (sender, e) => + { + HttpContext httpContext = ((HttpApplication)sender).Context; + ProcessRequest(httpContext); + }; + + // todo: initialize request errors handler + // todo: initialize XML cache flush } public void Dispose() @@ -310,62 +319,5 @@ namespace Umbraco.Web #endregion - #region Initialize - - private static volatile bool _appDomainInitialized = false; - static readonly object AppDomainLock = new object(); - - /// - /// Initializes the application one time only - /// - void InitializeDomain() - { - if (!_appDomainInitialized) - { - lock (AppDomainLock) - { - if (!_appDomainInitialized) - { - Trace.TraceInformation("Initialize AppDomain"); - - //create the ApplicationContext - ApplicationContext.Current = new ApplicationContext(new PluginResolver()); - - //TODO: Why is this necessary? if the ApplicationContext is null, then its not ready - ApplicationContext.Current.IsReady = true; // fixme - - // Backwards compatibility - set the path and URL type for ClientDependency 1.5.1 [LK] - ClientDependency.Core.CompositeFiles.Providers.XmlFileMapper.FileMapVirtualFolder = "~/App_Data/TEMP/ClientDependency"; - ClientDependency.Core.CompositeFiles.Providers.BaseCompositeFileProcessingProvider.UrlTypeDefault = ClientDependency.Core.CompositeFiles.Providers.CompositeUrlType.Base64QueryStrings; - - _appDomainInitialized = true; - } - Trace.TraceInformation("AppDomain is initialized"); - } - } - } - - void InitializeApplication(HttpApplication app) - { - // we can't do in in module.Init because we need HttpContext. - app.BeginRequest += (sender, e) => - { - Trace.TraceInformation("Welcome to Umbraco!"); - InitializeDomain(); - }; - - // used to be done in PostAuthorizeRequest but then it disabled OutputCaching due - // to rewriting happening too early in the chain (Alex Norcliffe 2010-02). - app.PostResolveRequestCache += (sender, e) => - { - HttpContext httpContext = ((HttpApplication)sender).Context; - ProcessRequest(httpContext); - }; - - // todo: initialize request errors handler - // todo: initialize XML cache flush - } - - #endregion } }