diff --git a/src/Umbraco.Web/NiceUrlResolver.cs b/src/Umbraco.Web/NiceUrlResolver.cs index 1e7da3b26e..57d5e2f78c 100644 --- a/src/Umbraco.Web/NiceUrlResolver.cs +++ b/src/Umbraco.Web/NiceUrlResolver.cs @@ -12,16 +12,14 @@ namespace Umbraco.Web /// internal class NiceUrlResolver { - public NiceUrlResolver(ContentStore contentStore, UmbracoContext umbracoContext, IRoutesCache routesCache) + public NiceUrlResolver(ContentStore contentStore, UmbracoContext umbracoContext) { _umbracoContext = umbracoContext; _contentStore = contentStore; - _routesCache = routesCache; } private readonly UmbracoContext _umbracoContext; private readonly ContentStore _contentStore; - private readonly IRoutesCache _routesCache; // note: this could be a parameter... const string UrlNameProperty = "@urlName"; @@ -41,7 +39,7 @@ namespace Umbraco.Web // will not read cache if previewing! var route = !_umbracoContext.InPreviewMode - ? _routesCache.GetRoute(nodeId) + ? _umbracoContext.RoutesCache.GetRoute(nodeId) : null; if (route != null) @@ -94,7 +92,7 @@ namespace Umbraco.Web if (!_umbracoContext.InPreviewMode) { - _routesCache.Store(nodeId, route); // will not write if previewing + _umbracoContext.RoutesCache.Store(nodeId, route); // will not write if previewing } return FormatUrl(domain, path); diff --git a/src/Umbraco.Web/PluginResolverExtensions.cs b/src/Umbraco.Web/PluginResolverExtensions.cs index 102172f15f..9bbab2bb1c 100644 --- a/src/Umbraco.Web/PluginResolverExtensions.cs +++ b/src/Umbraco.Web/PluginResolverExtensions.cs @@ -13,7 +13,7 @@ namespace Umbraco.Web public static class PluginResolverExtensions { - private static volatile IEnumerable _lookups; + private static volatile IEnumerable _lookups; private static readonly object Locker = new object(); /// @@ -21,7 +21,7 @@ namespace Umbraco.Web /// /// /// - internal static IEnumerable ResolveLookups(this PluginResolver plugins) + internal static IEnumerable ResolveLookups(this PluginResolver plugins) { if (_lookups == null) { @@ -29,22 +29,7 @@ namespace Umbraco.Web { if (_lookups == null) { - var lookupTypes = TypeFinder.FindClassesOfType(); - var lookups = new List(); - foreach (var l in lookupTypes) - { - try - { - var typeInstance = Activator.CreateInstance(l) as ILookup; - lookups.Add(typeInstance); - } - catch (Exception ex) - { - Log.Add(LogTypes.Error, -1, "Error loading ILookup: " + ex.ToString()); - } - } - //set the global - _lookups = lookups; + _lookups = TypeFinder.FindClassesOfType(); } } } diff --git a/src/Umbraco.Web/Routing/DocumentRequest.cs b/src/Umbraco.Web/Routing/DocumentRequest.cs index bb51181849..af62b651ef 100644 --- a/src/Umbraco.Web/Routing/DocumentRequest.cs +++ b/src/Umbraco.Web/Routing/DocumentRequest.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.Diagnostics; // legacy +using umbraco.BusinessLogic; using umbraco.cms.businesslogic.web; using umbraco.cms.businesslogic.template; using umbraco.cms.businesslogic.member; @@ -16,12 +17,9 @@ namespace Umbraco.Web.Routing { static readonly TraceSource Trace = new TraceSource("DocumentRequest"); - public DocumentRequest(Uri uri, RoutingEnvironment lookups, UmbracoContext umbracoContext, NiceUrlResolver niceUrlResolver) + public DocumentRequest(Uri uri, RoutingContext routingContext) { - // register lookups - _environment = lookups; - UmbracoContext = umbracoContext; - _niceUrlResolver = niceUrlResolver; + RoutingContext = routingContext; // prepare the host var host = uri.Host; @@ -55,9 +53,6 @@ namespace Umbraco.Web.Routing this.QueryString = uri.Query.TrimStart('?'); } - readonly RoutingEnvironment _environment; - private readonly NiceUrlResolver _niceUrlResolver; - /// /// the id of the requested node, if any, else zero. /// @@ -71,9 +66,9 @@ namespace Umbraco.Web.Routing #region Properties /// - /// Returns the current UmbracoContext + /// Returns the current RoutingContext /// - public UmbracoContext UmbracoContext { get; private set; } + public RoutingContext RoutingContext { get; private set; } /// /// Gets the request host name. @@ -128,7 +123,7 @@ namespace Umbraco.Web.Routing _node = value; this.Template = null; if (_node != null) - _nodeId = int.Parse(_environment.ContentStore.GetNodeProperty(_node, "@id")); + _nodeId = int.Parse(RoutingContext.ContentStore.GetNodeProperty(_node, "@id")); else _nodeId = 0; } @@ -251,8 +246,22 @@ namespace Umbraco.Web.Routing // the first successful lookup, if any, will set this.Node, and may also set this.Template // some lookups may implement caching Trace.TraceInformation("{0}Begin lookup", tracePrefix); - var lookups = _environment.RouteLookups.GetLookups(); - lookups.Any(lookup => lookup.LookupDocument(this)); + var lookups = RoutingContext.RouteLookups.GetLookups(); + lookups.Any(lookup => + { + //create the instance + try + { + var instance = (ILookup)Activator.CreateInstance(lookup); + return instance.LookupDocument(this); + } + catch (Exception ex) + { + Log.Add(LogTypes.Error, -1, "Error loading ILookup: " + ex.ToString()); + return false; + } + }); + Trace.TraceInformation("{0}End lookup, {1}", tracePrefix, (this.HasNode ? "a document was found" : "no document was found")); // fixme - not handling umbracoRedirect @@ -292,7 +301,7 @@ namespace Umbraco.Web.Routing Trace.TraceInformation("{0}No document, try notFound lookup", tracePrefix); // if it fails then give up, there isn't much more that we can do - if (_environment.LookupNotFound == null || !_environment.LookupNotFound.LookupDocument(this)) + if (RoutingContext.LookupNotFound == null || !RoutingContext.LookupNotFound.LookupDocument(this)) { Trace.TraceInformation("{0}Failed to find a document, give up", tracePrefix); break; @@ -344,7 +353,7 @@ namespace Umbraco.Web.Routing throw new InvalidOperationException("There is no node."); bool redirect = false; - string internalRedirect = _environment.ContentStore.GetNodeProperty(this.Node, "umbracoInternalRedirectId"); + string internalRedirect = RoutingContext.ContentStore.GetNodeProperty(this.Node, "umbracoInternalRedirectId"); if (!string.IsNullOrWhiteSpace(internalRedirect)) { @@ -368,7 +377,7 @@ namespace Umbraco.Web.Routing else { // redirect to another page - var node = _environment.ContentStore.GetNodeById(internalRedirectId); + var node = RoutingContext.ContentStore.GetNodeById(internalRedirectId); this.Node = node; if (node != null) { @@ -396,7 +405,7 @@ namespace Umbraco.Web.Routing if (this.Node == null) throw new InvalidOperationException("There is no node."); - var path = _environment.ContentStore.GetNodeProperty(this.Node, "@path"); + var path = RoutingContext.ContentStore.GetNodeProperty(this.Node, "@path"); if (Access.IsProtected(this.NodeId, path)) { @@ -409,14 +418,14 @@ namespace Umbraco.Web.Routing Trace.TraceInformation("{0}Not logged in, redirect to login page", tracePrefix); var loginPageId = Access.GetLoginPage(path); if (loginPageId != this.NodeId) - this.Node = _environment.ContentStore.GetNodeById(loginPageId); + this.Node = RoutingContext.ContentStore.GetNodeById(loginPageId); } else if (!Access.HasAccces(this.NodeId, user.ProviderUserKey)) { Trace.TraceInformation("{0}Current member has not access, redirect to error page", tracePrefix); var errorPageId = Access.GetErrorPage(path); if (errorPageId != this.NodeId) - this.Node = _environment.ContentStore.GetNodeById(errorPageId); + this.Node = RoutingContext.ContentStore.GetNodeById(errorPageId); } else { @@ -439,9 +448,9 @@ namespace Umbraco.Web.Routing if (this.Node == null) throw new InvalidOperationException("There is no node."); - var templateAlias = UmbracoContext.HttpContext.Request.QueryString["altTemplate"]; + var templateAlias = RoutingContext.UmbracoContext.HttpContext.Request.QueryString["altTemplate"]; if (string.IsNullOrWhiteSpace(templateAlias)) - templateAlias = UmbracoContext.HttpContext.Request.Form["altTemplate"]; + templateAlias = RoutingContext.UmbracoContext.HttpContext.Request.Form["altTemplate"]; // fixme - we might want to support cookies?!? NO but provide a hook to change the template @@ -449,7 +458,7 @@ namespace Umbraco.Web.Routing { if (string.IsNullOrWhiteSpace(templateAlias)) { - templateAlias = _environment.ContentStore.GetNodeProperty(this.Node, "@template"); + templateAlias = RoutingContext.ContentStore.GetNodeProperty(this.Node, "@template"); Trace.TraceInformation("{0}Look for template id={1}", tracePrefix, templateAlias); int templateId; if (!int.TryParse(templateAlias, out templateId)) @@ -491,11 +500,11 @@ namespace Umbraco.Web.Routing if (this.HasNode) { int redirectId; - if (!int.TryParse(_environment.ContentStore.GetNodeProperty(this.Node, "umbracoRedirect"), out redirectId)) + if (!int.TryParse(RoutingContext.ContentStore.GetNodeProperty(this.Node, "umbracoRedirect"), out redirectId)) redirectId = -1; string redirectUrl = "#"; if (redirectId > 0) - redirectUrl = _niceUrlResolver.GetNiceUrl(redirectId); + redirectUrl = RoutingContext.NiceUrlResolver.GetNiceUrl(redirectId); if (redirectUrl != "#") this.RedirectUrl = redirectUrl; } diff --git a/src/Umbraco.Web/Routing/LookupByAlias.cs b/src/Umbraco.Web/Routing/LookupByAlias.cs index 8d9cf2c081..153520106a 100644 --- a/src/Umbraco.Web/Routing/LookupByAlias.cs +++ b/src/Umbraco.Web/Routing/LookupByAlias.cs @@ -13,14 +13,9 @@ namespace Umbraco.Web.Routing [LookupWeight(50)] internal class LookupByAlias : ILookup { - public LookupByAlias(ContentStore contentStore) - { - _contentStore = contentStore; - } - + static readonly TraceSource Trace = new TraceSource("LookupByAlias"); - readonly ContentStore _contentStore; public bool LookupDocument(DocumentRequest docreq) { @@ -28,7 +23,7 @@ namespace Umbraco.Web.Routing if (docreq.Path != "/") // no alias if "/" { - node = _contentStore.GetNodeByUrlAlias(docreq.HasDomain ? docreq.Domain.RootNodeId : 0, docreq.Path); + node = docreq.RoutingContext.ContentStore.GetNodeByUrlAlias(docreq.HasDomain ? docreq.Domain.RootNodeId : 0, docreq.Path); if (node != null) { Trace.TraceInformation("Path \"{0}\" is an alias for id={1}", docreq.Path, docreq.NodeId); diff --git a/src/Umbraco.Web/Routing/LookupById.cs b/src/Umbraco.Web/Routing/LookupById.cs index 8370df4ecc..61f63f7e77 100644 --- a/src/Umbraco.Web/Routing/LookupById.cs +++ b/src/Umbraco.Web/Routing/LookupById.cs @@ -10,24 +10,9 @@ namespace Umbraco.Web.Routing [LookupWeight(20)] internal class LookupById : ILookup { - public LookupById(ContentStore contentStore) - { - _contentStore = contentStore; - } - + static readonly TraceSource Trace = new TraceSource("LookupById"); - readonly ContentStore _contentStore; - - ////[Import] - //IContentStore ContentStoreImport - //{ - // set { _contentStore = value; } - //} - - //public LookupById() - //{ } - public bool LookupDocument(DocumentRequest docreq) { XmlNode node = null; @@ -43,7 +28,7 @@ namespace Umbraco.Web.Routing if (nodeId > 0) { Trace.TraceInformation("Id={0}", nodeId); - node = _contentStore.GetNodeById(nodeId); + node = docreq.RoutingContext.ContentStore.GetNodeById(nodeId); if (node != null) { docreq.Node = node; diff --git a/src/Umbraco.Web/Routing/LookupByPath.cs b/src/Umbraco.Web/Routing/LookupByPath.cs index 30dc31f546..62590276e2 100644 --- a/src/Umbraco.Web/Routing/LookupByPath.cs +++ b/src/Umbraco.Web/Routing/LookupByPath.cs @@ -9,17 +9,9 @@ namespace Umbraco.Web.Routing [LookupWeight(10)] internal class LookupByPath : ILookup { - public LookupByPath(ContentStore contentStore, IRoutesCache routesCache) - { - ContentStore = contentStore; - RoutesCache = routesCache; - } - + static readonly TraceSource Trace = new TraceSource("LookupByPath"); - protected ContentStore ContentStore; - protected IRoutesCache RoutesCache; - public virtual bool LookupDocument(DocumentRequest docreq) { var route = docreq.HasDomain ? (docreq.Domain.RootNodeId.ToString() + docreq.Path) : docreq.Path; @@ -32,15 +24,15 @@ namespace Umbraco.Web.Routing Trace.TraceInformation("Test route \"{0}\"", route); //return '0' if in preview mode! - var nodeId = !docreq.UmbracoContext.InPreviewMode - ? RoutesCache.GetNodeId(route) + var nodeId = !docreq.RoutingContext.UmbracoContext.InPreviewMode + ? docreq.RoutingContext.UmbracoContext.RoutesCache.GetNodeId(route) : 0; XmlNode node = null; if (nodeId > 0) { - node = ContentStore.GetNodeById(nodeId); + node = docreq.RoutingContext.ContentStore.GetNodeById(nodeId); if (node != null) { docreq.Node = node; @@ -48,22 +40,22 @@ namespace Umbraco.Web.Routing } else { - RoutesCache.ClearNode(nodeId); + docreq.RoutingContext.UmbracoContext.RoutesCache.ClearNode(nodeId); } } if (node == null) { Trace.TraceInformation("Cache miss, query"); - node = ContentStore.GetNodeByRoute(route); + node = docreq.RoutingContext.ContentStore.GetNodeByRoute(route); if (node != null) { docreq.Node = node; Trace.TraceInformation("Query matches, id={0}", docreq.NodeId); - if (!docreq.UmbracoContext.InPreviewMode) + if (!docreq.RoutingContext.UmbracoContext.InPreviewMode) { - RoutesCache.Store(docreq.NodeId, route); // will not write if previewing + docreq.RoutingContext.UmbracoContext.RoutesCache.Store(docreq.NodeId, route); // will not write if previewing } } diff --git a/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs b/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs index 11454bcdb2..6c3a105e87 100644 --- a/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs +++ b/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs @@ -11,12 +11,7 @@ namespace Umbraco.Web.Routing [LookupWeight(30)] internal class LookupByPathWithTemplate : LookupByPath, ILookup { - static readonly TraceSource Trace = new TraceSource("LookupByPathWithTemplate"); - - public LookupByPathWithTemplate(ContentStore contentStore, IRoutesCache routesCache) - : base(contentStore, routesCache) - { - } + static readonly TraceSource Trace = new TraceSource("LookupByPathWithTemplate"); public override bool LookupDocument(DocumentRequest docreq) { diff --git a/src/Umbraco.Web/Routing/LookupByProfile.cs b/src/Umbraco.Web/Routing/LookupByProfile.cs index c3044349e7..cbf66cfae6 100644 --- a/src/Umbraco.Web/Routing/LookupByProfile.cs +++ b/src/Umbraco.Web/Routing/LookupByProfile.cs @@ -14,15 +14,7 @@ namespace Umbraco.Web.Routing [LookupWeight(40)] internal class LookupByProfile : LookupByPath, ILookup { - private readonly UmbracoContext _umbracoContext; - static readonly TraceSource Trace = new TraceSource("LookupByProfile"); - - - public LookupByProfile(ContentStore contentStore, IRoutesCache routesCache, UmbracoContext umbracoContext) - : base(contentStore, routesCache) - { - _umbracoContext = umbracoContext; - } + static readonly TraceSource Trace = new TraceSource("LookupByProfile"); public override bool LookupDocument(DocumentRequest docreq) { @@ -44,7 +36,10 @@ namespace Umbraco.Web.Routing node = LookupDocumentNode(docreq, route); if (node != null) - _umbracoContext.HttpContext.Items["umbMemberLogin"] = memberLogin; + { + //TODO: Should be handled by Context Items class manager (http://issues.umbraco.org/issue/U4-61) + docreq.RoutingContext.UmbracoContext.HttpContext.Items["umbMemberLogin"] = memberLogin; + } else Trace.TraceInformation("No document matching profile path?"); } diff --git a/src/Umbraco.Web/Routing/LookupFor404.cs b/src/Umbraco.Web/Routing/LookupFor404.cs index 08bc6ec0cd..4b29d61c16 100644 --- a/src/Umbraco.Web/Routing/LookupFor404.cs +++ b/src/Umbraco.Web/Routing/LookupFor404.cs @@ -11,18 +11,12 @@ namespace Umbraco.Web.Routing { internal class LookupFor404 : ILookupNotFound { - public LookupFor404(ContentStore contentStore) - { - _contentStore = contentStore; - } - + static TraceSource _trace = new TraceSource("LookupByAlias"); - private readonly ContentStore _contentStore; - public bool LookupDocument(DocumentRequest docRequest) { - docRequest.Node = HandlePageNotFound(docRequest.Path); + docRequest.Node = HandlePageNotFound(docRequest); return docRequest.HasNode; } @@ -30,17 +24,17 @@ namespace Umbraco.Web.Routing // copied from presentation/requestHandler // temporary!! - XmlNode HandlePageNotFound(string url) + XmlNode HandlePageNotFound(DocumentRequest docRequest) { - HttpContext.Current.Trace.Write("NotFoundHandler", string.Format("Running for url='{0}'.", url)); + HttpContext.Current.Trace.Write("NotFoundHandler", string.Format("Running for url='{0}'.", docRequest.Path)); XmlNode currentPage = null; foreach (var handler in GetNotFoundHandlers()) { - if (handler.Execute(url) && handler.redirectID > 0) + if (handler.Execute(docRequest.Path) && handler.redirectID > 0) { //currentPage = umbracoContent.GetElementById(handler.redirectID.ToString()); - currentPage = _contentStore.GetNodeById(handler.redirectID); + currentPage = docRequest.RoutingContext.ContentStore.GetNodeById(handler.redirectID); // FIXME - could it be null? diff --git a/src/Umbraco.Web/Routing/RouteLookups.cs b/src/Umbraco.Web/Routing/RouteLookups.cs index 9e6671c9e0..6dd33576e4 100644 --- a/src/Umbraco.Web/Routing/RouteLookups.cs +++ b/src/Umbraco.Web/Routing/RouteLookups.cs @@ -7,11 +7,11 @@ using Umbraco.Core; namespace Umbraco.Web.Routing { /// - /// Represents a collection of ILookups used for routing that are registered in the application + /// Represents a collection of ILookup types used for routing that are registered in the application /// internal class RouteLookups { - private static readonly List Lookups = new List(); + private static readonly List Lookups = new List(); private static readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim(); /// @@ -19,7 +19,7 @@ namespace Umbraco.Web.Routing /// public static RouteLookups Current { get; internal set; } - internal RouteLookups(IEnumerable lookups) + internal RouteLookups(IEnumerable lookups) { Lookups.AddRange(SortByWeight(lookups)); } @@ -28,7 +28,7 @@ namespace Umbraco.Web.Routing /// Returns all of the lookups /// /// - public IEnumerable GetLookups() + public IEnumerable GetLookups() { return Lookups; } @@ -46,14 +46,27 @@ namespace Umbraco.Web.Routing } } + /// + /// Adds a new lookup to the end of the list + /// + /// + public void AddLookup() + where T : ILookup + { + AddLookup(typeof (T)); + } + /// /// Adds a new lookup to the end of the list /// /// - public void AddLookup(ILookup lookup) - { + public void AddLookup(Type lookup) + { + if (!typeof(ILookup).IsAssignableFrom(lookup)) + throw new InvalidOperationException("The type specified is not of type " + typeof (ILookup)); + if (CheckExists(lookup)) - throw new InvalidOperationException("The lookup type " + lookup.GetType() + " already exists in the lookup collection"); + throw new InvalidOperationException("The lookup type " + lookup + " already exists in the lookup collection"); using (new WriteLock(Lock)) { @@ -66,10 +79,10 @@ namespace Umbraco.Web.Routing /// /// /// - public void InsertLookup(int index, ILookup lookup) + public void InsertLookup(int index, Type lookup) { if (CheckExists(lookup)) - throw new InvalidOperationException("The lookup type " + lookup.GetType() + " already exists in the lookup collection"); + throw new InvalidOperationException("The lookup type " + lookup + " already exists in the lookup collection"); using (new WriteLock(Lock)) { @@ -82,9 +95,9 @@ namespace Umbraco.Web.Routing /// /// /// - private static bool CheckExists(ILookup lookup) + private static bool CheckExists(Type lookup) { - return Lookups.Any(x => x.GetType() == lookup.GetType()); + return Lookups.Any(x => x == lookup); } /// @@ -92,11 +105,11 @@ namespace Umbraco.Web.Routing /// /// /// - private static IEnumerable SortByWeight(IEnumerable lookups) + private static IEnumerable SortByWeight(IEnumerable lookups) { return lookups.OrderBy(x => { - var attribute = x.GetType().GetCustomAttributes(true).OfType().SingleOrDefault(); + var attribute = x.GetCustomAttributes(true).OfType().SingleOrDefault(); return attribute == null ? LookupWeightAttribute.DefaultWeight : attribute.Weight; }).ToList(); } diff --git a/src/Umbraco.Web/Routing/RoutingEnvironment.cs b/src/Umbraco.Web/Routing/RoutingContext.cs similarity index 58% rename from src/Umbraco.Web/Routing/RoutingEnvironment.cs rename to src/Umbraco.Web/Routing/RoutingContext.cs index 0c5d770e86..7f2013a0d9 100644 --- a/src/Umbraco.Web/Routing/RoutingEnvironment.cs +++ b/src/Umbraco.Web/Routing/RoutingContext.cs @@ -8,23 +8,26 @@ namespace Umbraco.Web.Routing /// represents a request for one specified Umbraco document to be rendered by one specified template, /// using one particular culture. /// - internal class RoutingEnvironment + internal class RoutingContext { - public RoutingEnvironment( + public RoutingContext( + UmbracoContext umbracoContext, RouteLookups lookups, ILookupNotFound lookupNotFound, - ContentStore contentStore) + ContentStore contentStore, + NiceUrlResolver niceUrlResolver) { - RouteLookups = lookups; + UmbracoContext = umbracoContext; + RouteLookups = lookups; LookupNotFound = lookupNotFound; ContentStore = contentStore; + NiceUrlResolver = niceUrlResolver; } + public UmbracoContext UmbracoContext { get; private set; } public RouteLookups RouteLookups { get; private set; } - public ILookupNotFound LookupNotFound { get; private set; } - public ContentStore ContentStore { get; private set; } - + public NiceUrlResolver NiceUrlResolver { get; private set; } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 3b5d82ee48..0dae665f09 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -256,7 +256,7 @@ - + database.ascx diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 6d6729b7c7..abb13a45b1 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -32,18 +32,23 @@ namespace Umbraco.Web /// private static UmbracoContext _umbracoContext; - /// - /// Creates a new Umbraco context. - /// - /// - /// - internal UmbracoContext(HttpContextBase httpContext, ApplicationContext applicationContext) + /// + /// Creates a new Umbraco context. + /// + /// + /// + /// + internal UmbracoContext( + HttpContextBase httpContext, + ApplicationContext applicationContext, + IRoutesCache routesCache) { if (httpContext == null) throw new ArgumentNullException("httpContext"); if (applicationContext == null) throw new ArgumentNullException("applicationContext"); HttpContext = httpContext; Application = applicationContext; + RoutesCache = routesCache; } /// @@ -91,7 +96,9 @@ namespace Umbraco.Web /// public ApplicationContext Application { get; private set; } - /// + internal IRoutesCache RoutesCache { get; private set; } + + /// /// Gets/sets the original URL of the request /// internal Uri OriginalUrl { get; set; } @@ -124,17 +131,7 @@ namespace Umbraco.Web /// /// Gets/sets the DocumentRequest object /// - internal DocumentRequest DocumentRequest { get; set; } - - /// - /// Gets/sets the NiceUrlResolver object - /// - internal NiceUrlResolver NiceUrlResolver { get; set; } - - /// - /// Gets/sets the RoutingEnvironment object - /// - internal RoutingEnvironment RoutingEnvironment { get; set; } + internal DocumentRequest DocumentRequest { get; set; } /// /// Exposes the HttpContext for the current request diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index bcd976c8d3..aeb2754e48 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -33,29 +33,28 @@ namespace Umbraco.Web httpContext.Response.AddHeader("X-Umbraco-Version", string.Format("{0}.{1}", GlobalSettings.VersionMajor, GlobalSettings.VersionMinor)); //create the UmbracoContext singleton, one per request!! - var umbracoContext = new UmbracoContext(new HttpContextWrapper(httpContext), ApplicationContext.Current); + var umbracoContext = new UmbracoContext( + new HttpContextWrapper(httpContext), + ApplicationContext.Current, + RoutesCache.Current.GetProvider()); UmbracoContext.Current = umbracoContext; //create a content store var contentStore = new ContentStore(umbracoContext); //create the nice urls - var niceUrls = new NiceUrlResolver(contentStore, umbracoContext, RoutesCache.Current.GetProvider()); - //create the RoutingEnvironment (one per http request as it relies on the umbraco context!) - var routingEnvironment = new RoutingEnvironment( - RouteLookups.Current, - new LookupFor404(contentStore), - contentStore); + var niceUrls = new NiceUrlResolver(contentStore, umbracoContext); + //create the RoutingContext (one per http request) + var routingContext = new RoutingContext( + umbracoContext, + RouteLookups.Current, + new LookupFor404(), + contentStore, + niceUrls); // create the new document request which will cleanup the uri once and for all - var docreq = new DocumentRequest(uri, routingEnvironment, umbracoContext, niceUrls); + var docreq = new DocumentRequest(uri, routingContext); - //NOTE: we are putting these objects on the UmbracoContext because these might be handy for developers in the future to - // access if we make them public. - // initialize the DocumentRequest on the UmbracoContext (this is circular dependency!!!) + // initialize the DocumentRequest on the UmbracoContext (this is circular dependency but i think in this case is ok) umbracoContext.DocumentRequest = docreq; - // initialize the RoutingEnvironment on the UmbracoContext (this is circular dependency!!!) - umbracoContext.RoutingEnvironment = routingEnvironment; - // initialize the RoutingEnvironment on the UmbracoContext (this is circular dependency!!!) - umbracoContext.NiceUrlResolver = niceUrls; //create the LegacyRequestInitializer (one per http request as it relies on the umbraco context!) var legacyRequestInitializer = new LegacyRequestInitializer(umbracoContext);