diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs
index 1c688080ce..fca5ff2371 100644
--- a/src/Umbraco.Web/UmbracoContext.cs
+++ b/src/Umbraco.Web/UmbracoContext.cs
@@ -125,6 +125,7 @@ namespace Umbraco.Web
if (umbracoSettings == null) throw new ArgumentNullException("umbracoSettings");
if (urlProviders == null) throw new ArgumentNullException("urlProviders");
+ //if there's already a singleton, and we're not replacing then there's no need to ensure anything
if (UmbracoContext.Current != null)
{
if (replaceContext == false)
@@ -132,6 +133,39 @@ namespace Umbraco.Web
UmbracoContext.Current._replacing = true;
}
+ var umbracoContext = CreateContext(httpContext, applicationContext, webSecurity, umbracoSettings, urlProviders, preview ?? false);
+
+ //assign the singleton
+ UmbracoContext.Current = umbracoContext;
+ return UmbracoContext.Current;
+ }
+
+ ///
+ /// Creates a standalone UmbracoContext instance
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// A new instance of UmbracoContext
+ ///
+ public static UmbracoContext CreateContext(
+ HttpContextBase httpContext,
+ ApplicationContext applicationContext,
+ WebSecurity webSecurity,
+ IUmbracoSettingsSection umbracoSettings,
+ IEnumerable urlProviders,
+ bool preview)
+ {
+ if (httpContext == null) throw new ArgumentNullException("httpContext");
+ if (applicationContext == null) throw new ArgumentNullException("applicationContext");
+ if (webSecurity == null) throw new ArgumentNullException("webSecurity");
+ if (umbracoSettings == null) throw new ArgumentNullException("umbracoSettings");
+ if (urlProviders == null) throw new ArgumentNullException("urlProviders");
+
var umbracoContext = new UmbracoContext(
httpContext,
applicationContext,
@@ -142,15 +176,15 @@ namespace Umbraco.Web
// create the RoutingContext, and assign
var routingContext = new RoutingContext(
umbracoContext,
-
+
//TODO: Until the new cache is done we can't really expose these to override/mock
new Lazy>(() => ContentFinderResolver.Current.Finders),
new Lazy(() => ContentLastChanceFinderResolver.Current.Finder),
-
+
// create the nice urls provider
// there's one per request because there are some behavior parameters that can be changed
new Lazy(
- () => new UrlProvider(
+ () => new UrlProvider(
umbracoContext,
umbracoSettings.WebRouting,
urlProviders),
@@ -159,9 +193,7 @@ namespace Umbraco.Web
//assign the routing context back
umbracoContext.RoutingContext = routingContext;
- //assign the singleton
- UmbracoContext.Current = umbracoContext;
- return UmbracoContext.Current;
+ return umbracoContext;
}
///
@@ -460,18 +492,9 @@ namespace Umbraco.Web
protected override void DisposeResources()
{
Security.DisposeIfDisposable();
- Security = null;
- _umbracoContext = null;
- //ensure not to dispose this!
- Application = null;
- //Before we set these to null but in fact these are application lifespan singletons so
- //there's no reason we need to set them to null and this also caused a problem with packages
- //trying to access the cache properties on RequestEnd.
- //http://issues.umbraco.org/issue/U4-2734
- //http://our.umbraco.org/projects/developer-tools/301-url-tracker/version-2/44327-Issues-with-URL-Tracker-in-614
- //ContentCache = null;
- //MediaCache = null;
+ //If not running in a web ctx, ensure the thread based instance is nulled
+ _umbracoContext = null;
}
}
}
\ No newline at end of file