From abceda7750b7e131bc3cc3c3a71e99c60e468b9e Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 14 Feb 2019 09:49:45 +0100 Subject: [PATCH] Kill UmbracoContext.Current --- .../UmbracoContextCache.cs | 2 +- .../PublishedContentLanguageVariantTests.cs | 36 +++++++++---------- .../PublishedContentMoreTests.cs | 21 +++++------ .../Testing/TestingTests/MockTests.cs | 2 +- .../config/splashes/NoNodes.aspx.cs | 3 +- .../BatchedDatabaseServerMessenger.cs | 3 +- .../IsCurrentUserModelFilterAttribute.cs | 3 +- .../UserGroupAuthorizationAttribute.cs | 2 +- src/Umbraco.Web/Editors/TourController.cs | 2 +- src/Umbraco.Web/HtmlHelperRenderExtensions.cs | 10 +++--- .../Macros/PartialViewMacroEngine.cs | 5 +-- .../Models/Mapping/ActionButtonsResolver.cs | 5 +-- .../Mapping/ContentTypeBasicResolver.cs | 5 +-- .../EnsurePublishedContentRequestAttribute.cs | 8 ++--- .../Mvc/RedirectToUmbracoPageResult.cs | 15 ++++---- .../Mvc/UmbracoViewPageOfTModel.cs | 6 ++-- .../Mvc/UmbracoVirtualNodeRouteHandler.cs | 2 +- .../MarkdownEditorValueConverter.cs | 3 +- .../MemberPickerValueConverter.cs | 3 +- .../MultiNodeTreePickerValueConverter.cs | 3 +- .../RteMacroRenderingValueConverter.cs | 3 +- .../TextStringValueConverter.cs | 3 +- src/Umbraco.Web/PublishedContentExtensions.cs | 14 ++++---- .../PublishedContentNotFoundHandler.cs | 5 +-- .../Routing/RedirectTrackingComponent.cs | 22 ++++++------ src/Umbraco.Web/Routing/UrlProvider.cs | 3 +- src/Umbraco.Web/UmbracoContext.cs | 8 +---- src/Umbraco.Web/UmbracoInjectedModule.cs | 12 +++---- src/Umbraco.Web/UrlHelperRenderExtensions.cs | 4 +-- .../AppendCurrentEventMessagesAttribute.cs | 2 +- .../AppendUserModifiedHeaderAttribute.cs | 3 +- ...EnsureUserPermissionForContentAttribute.cs | 2 +- .../EnsureUserPermissionForMediaAttribute.cs | 4 +-- .../FilterAllowedOutgoingMediaAttribute.cs | 2 +- .../OutgoingEditorModelEventAttribute.cs | 5 +-- 35 files changed, 121 insertions(+), 110 deletions(-) diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/UmbracoContextCache.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/UmbracoContextCache.cs index fc6dbe3f30..5d48e9eae3 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/UmbracoContextCache.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/UmbracoContextCache.cs @@ -13,7 +13,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache { get { - var umbracoContext = UmbracoContext.Current; + var umbracoContext = Umbraco.Web.Composing.Current.UmbracoContext; // will get or create a value // a ConditionalWeakTable is thread-safe diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs index ac1c57d409..108bfb9f18 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs @@ -4,12 +4,12 @@ using System.Collections.ObjectModel; using System.Linq; using Moq; using NUnit.Framework; -using Umbraco.Core.Composing; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; using Umbraco.Tests.Testing; using Umbraco.Web; +using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Tests.PublishedContent { @@ -186,7 +186,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_For_Populated_Requested_Language() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First(); var value = content.Value("welcomeText", "en-US"); Assert.AreEqual("Welcome", value); } @@ -194,7 +194,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_For_Populated_Requested_Non_Default_Language() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First(); var value = content.Value("welcomeText", "de"); Assert.AreEqual("Willkommen", value); } @@ -202,7 +202,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Do_Not_Get_Content_For_Unpopulated_Requested_Language_Without_Fallback() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First(); var value = content.Value("welcomeText", "fr"); Assert.IsNull(value); } @@ -210,7 +210,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Do_Not_Get_Content_For_Unpopulated_Requested_Language_With_Fallback_Unless_Requested() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First(); var value = content.Value("welcomeText", "es"); Assert.IsNull(value); } @@ -218,7 +218,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_For_Unpopulated_Requested_Language_With_Fallback() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First(); var value = content.Value("welcomeText", "es", fallback: Fallback.ToLanguage); Assert.AreEqual("Welcome", value); } @@ -226,7 +226,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_For_Unpopulated_Requested_Language_With_Fallback_Over_Two_Levels() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First(); var value = content.Value("welcomeText", "it", fallback: Fallback.To(Fallback.Language, Fallback.Ancestors)); Assert.AreEqual("Welcome", value); } @@ -234,7 +234,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Do_Not_GetContent_For_Unpopulated_Requested_Language_With_Fallback_Over_That_Loops() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First(); var value = content.Value("welcomeText", "no", fallback: Fallback.ToLanguage); Assert.IsNull(value); } @@ -242,7 +242,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Do_Not_Get_Content_Recursively_Unless_Requested() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); var value = content.Value("welcomeText2"); Assert.IsNull(value); } @@ -250,7 +250,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_Recursively() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); var value = content.Value("welcomeText2", fallback: Fallback.ToAncestors); Assert.AreEqual("Welcome", value); } @@ -258,7 +258,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Do_Not_Get_Content_Recursively_Unless_Requested2() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First().Children.First().Children().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First().Children().First(); Assert.IsNull(content.GetProperty("welcomeText2")); var value = content.Value("welcomeText2"); Assert.IsNull(value); @@ -267,7 +267,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_Recursively2() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First().Children.First().Children().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First().Children().First(); Assert.IsNull(content.GetProperty("welcomeText2")); var value = content.Value("welcomeText2", fallback: Fallback.ToAncestors); Assert.AreEqual("Welcome", value); @@ -276,7 +276,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_Recursively3() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First().Children.First().Children().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First().Children().First(); Assert.IsNull(content.GetProperty("noprop")); var value = content.Value("noprop", fallback: Fallback.ToAncestors); // property has no value but we still get the value (ie, the converter would do something) @@ -287,7 +287,7 @@ namespace Umbraco.Tests.PublishedContent public void Can_Get_Content_With_Recursive_Priority() { Current.VariationContextAccessor.VariationContext = new VariationContext("nl"); - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); var value = content.Value("welcomeText", "nl", fallback: Fallback.To(Fallback.Ancestors, Fallback.Language)); @@ -298,7 +298,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Get_Content_With_Fallback_Language_Priority() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); var value = content.Value("welcomeText", "nl", fallback: Fallback.ToLanguage); // No Dutch value is directly assigned. Check has fallen back to English value from language variant. @@ -308,14 +308,14 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Throws_For_Non_Supported_Fallback() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); Assert.Throws(() => content.Value("welcomeText", "nl", fallback: Fallback.To(999))); } [Test] public void Can_Fallback_To_Default_Value() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); // no Dutch value is assigned, so getting null var value = content.Value("welcomeText", "nl"); @@ -333,7 +333,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Can_Have_Custom_Default_Value() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First().Children.First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First().Children.First(); // HACK: the value, pretend the converter would return something var prop = content.GetProperty("welcomeText") as SolidPublishedPropertyWithLanguageVariants; diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs index 0dcc4bea99..b2f1f311c3 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs @@ -5,6 +5,7 @@ using Umbraco.Core.Models.PublishedContent; using Umbraco.Web; using Umbraco.Core; using Umbraco.Tests.Testing; +using Umbraco.Web.Composing; namespace Umbraco.Tests.PublishedContent { @@ -95,14 +96,14 @@ namespace Umbraco.Tests.PublishedContent [Test] public void First() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot().First(); + var content = Current.UmbracoContext.ContentCache.GetAtRoot().First(); Assert.AreEqual("Content 1", content.Name); } [Test] public void Distinct() { - var items = UmbracoContext.Current.ContentCache.GetAtRoot() + var items = Current.UmbracoContext.ContentCache.GetAtRoot() .Distinct() .Distinct() .ToIndexedArray(); @@ -126,7 +127,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void OfType1() { - var items = UmbracoContext.Current.ContentCache.GetAtRoot() + var items = Current.UmbracoContext.ContentCache.GetAtRoot() .OfType() .Distinct() .ToIndexedArray(); @@ -137,7 +138,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void OfType2() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot() + var content = Current.UmbracoContext.ContentCache.GetAtRoot() .OfType() .Distinct() .ToIndexedArray(); @@ -148,7 +149,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void OfType() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot() + var content = Current.UmbracoContext.ContentCache.GetAtRoot() .OfType() .First(x => x.Prop1 == 1234); Assert.AreEqual("Content 2", content.Name); @@ -158,7 +159,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Position() { - var items = UmbracoContext.Current.ContentCache.GetAtRoot() + var items = Current.UmbracoContext.ContentCache.GetAtRoot() .Where(x => x.Value("prop1") == 1234) .ToIndexedArray(); @@ -173,7 +174,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void Issue() { - var content = UmbracoContext.Current.ContentCache.GetAtRoot() + var content = Current.UmbracoContext.ContentCache.GetAtRoot() .Distinct() .OfType(); @@ -181,12 +182,12 @@ namespace Umbraco.Tests.PublishedContent var first = where.First(); Assert.AreEqual(1234, first.Prop1); - var content2 = UmbracoContext.Current.ContentCache.GetAtRoot() + var content2 = Current.UmbracoContext.ContentCache.GetAtRoot() .OfType() .First(x => x.Prop1 == 1234); Assert.AreEqual(1234, content2.Prop1); - var content3 = UmbracoContext.Current.ContentCache.GetAtRoot() + var content3 = Current.UmbracoContext.ContentCache.GetAtRoot() .OfType() .First(); Assert.AreEqual(1234, content3.Prop1); @@ -195,7 +196,7 @@ namespace Umbraco.Tests.PublishedContent [Test] public void PublishedContentQueryTypedContentList() { - var query = new PublishedContentQuery(UmbracoContext.Current.PublishedSnapshot, UmbracoContext.Current.VariationContextAccessor); + var query = new PublishedContentQuery(Current.UmbracoContext.PublishedSnapshot, Current.UmbracoContext.VariationContextAccessor); var result = query.Content(new[] { 1, 2, 4 }).ToArray(); Assert.AreEqual(2, result.Length); Assert.AreEqual(1, result[0].Id); diff --git a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs index 652ac0ab30..b69451547e 100644 --- a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs +++ b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs @@ -44,7 +44,7 @@ namespace Umbraco.Tests.Testing.TestingTests public void Can_Mock_Umbraco_Context() { var umbracoContext = TestObjects.GetUmbracoContextMock(Current.UmbracoContextAccessor); - Assert.AreEqual(umbracoContext, UmbracoContext.Current); + Assert.AreEqual(umbracoContext, Current.UmbracoContext); } [Test] diff --git a/src/Umbraco.Web.UI/config/splashes/NoNodes.aspx.cs b/src/Umbraco.Web.UI/config/splashes/NoNodes.aspx.cs index 3dc1a2debf..3db0f0371b 100644 --- a/src/Umbraco.Web.UI/config/splashes/NoNodes.aspx.cs +++ b/src/Umbraco.Web.UI/config/splashes/NoNodes.aspx.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.WebPages; +using Umbraco.Web.Composing; namespace Umbraco.Web.UI.Config.Splashes { @@ -13,7 +14,7 @@ namespace Umbraco.Web.UI.Config.Splashes { base.OnInit(e); - var store = UmbracoContext.Current.ContentCache; + var store = Current.UmbracoContext.ContentCache; if (store.HasContent()) { //if there is actually content, go to the root diff --git a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs index ce0be7fbe6..76d7565862 100644 --- a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs +++ b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs @@ -12,6 +12,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Scoping; +using Umbraco.Web.Composing; namespace Umbraco.Web { @@ -102,7 +103,7 @@ namespace Umbraco.Web // try get the http context from the UmbracoContext, we do this because in the case we are launching an async // thread and we know that the cache refreshers will execute, we will ensure the UmbracoContext and therefore we // can get the http context from it - var httpContext = (UmbracoContext.Current == null ? null : UmbracoContext.Current.HttpContext) + var httpContext = (Current.UmbracoContext == null ? null : Current.UmbracoContext.HttpContext) // if this is null, it could be that an async thread is calling this method that we weren't aware of and the UmbracoContext // wasn't ensured at the beginning of the thread. We can try to see if the HttpContext.Current is available which might be // the case if the asp.net synchronization context has kicked in diff --git a/src/Umbraco.Web/Editors/Filters/IsCurrentUserModelFilterAttribute.cs b/src/Umbraco.Web/Editors/Filters/IsCurrentUserModelFilterAttribute.cs index 59a383dca6..b9c6eb45eb 100644 --- a/src/Umbraco.Web/Editors/Filters/IsCurrentUserModelFilterAttribute.cs +++ b/src/Umbraco.Web/Editors/Filters/IsCurrentUserModelFilterAttribute.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Net.Http; using System.Web.Http.Filters; +using Umbraco.Web.Composing; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.Editors.Filters @@ -14,7 +15,7 @@ namespace Umbraco.Web.Editors.Filters { if (actionExecutedContext.Response == null) return; - var user = UmbracoContext.Current.Security.CurrentUser; + var user = Current.UmbracoContext.Security.CurrentUser; if (user == null) return; var objectContent = actionExecutedContext.Response.Content as ObjectContent; diff --git a/src/Umbraco.Web/Editors/Filters/UserGroupAuthorizationAttribute.cs b/src/Umbraco.Web/Editors/Filters/UserGroupAuthorizationAttribute.cs index 4293c31660..3fc4c8cedc 100644 --- a/src/Umbraco.Web/Editors/Filters/UserGroupAuthorizationAttribute.cs +++ b/src/Umbraco.Web/Editors/Filters/UserGroupAuthorizationAttribute.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.Editors.Filters private UmbracoContext GetUmbracoContext() { - return _umbracoContext ?? UmbracoContext.Current; + return _umbracoContext ?? Composing.Current.UmbracoContext; } protected override bool IsAuthorized(HttpActionContext actionContext) diff --git a/src/Umbraco.Web/Editors/TourController.cs b/src/Umbraco.Web/Editors/TourController.cs index f2a546e407..a61926740a 100644 --- a/src/Umbraco.Web/Editors/TourController.cs +++ b/src/Umbraco.Web/Editors/TourController.cs @@ -71,7 +71,7 @@ namespace Umbraco.Web.Editors } } //Get all allowed sections for the current user - var allowedSections = UmbracoContext.Current.Security.CurrentUser.AllowedSections.ToList(); + var allowedSections = Composing.Current.UmbracoContext.Security.CurrentUser.AllowedSections.ToList(); var toursToBeRemoved = new List(); diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index 44d0cc27ca..dccc5594fa 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -63,12 +63,12 @@ namespace Umbraco.Web /// public static MvcHtmlString PreviewBadge(this HtmlHelper helper) { - if (UmbracoContext.Current.InPreviewMode) + if (Current.UmbracoContext.InPreviewMode) { var htmlBadge = String.Format(Current.Configs.Settings().Content.PreviewBadge, IOHelper.ResolveUrl(SystemDirectories.Umbraco), - UmbracoContext.Current.HttpContext.Server.UrlEncode(UmbracoContext.Current.HttpContext.Request.Path)); + Current.UmbracoContext.HttpContext.Server.UrlEncode(Current.UmbracoContext.HttpContext.Request.Path)); return new MvcHtmlString(htmlBadge); } return new MvcHtmlString(""); @@ -88,11 +88,11 @@ namespace Umbraco.Web var cacheKey = new StringBuilder(partialViewName); if (cacheByPage) { - if (UmbracoContext.Current == null) + if (Current.UmbracoContext == null) { throw new InvalidOperationException("Cannot cache by page if the UmbracoContext has not been initialized, this parameter can only be used in the context of an Umbraco request"); } - cacheKey.AppendFormat("{0}-", UmbracoContext.Current.PublishedRequest?.PublishedContent?.Id ?? 0); + cacheKey.AppendFormat("{0}-", Current.UmbracoContext.PublishedRequest?.PublishedContent?.Id ?? 0); } if (cacheByMember) { @@ -690,7 +690,7 @@ namespace Umbraco.Web if (string.IsNullOrEmpty(action)) throw new ArgumentNullOrEmptyException(nameof(action)); if (string.IsNullOrEmpty(controllerName)) throw new ArgumentNullOrEmptyException(nameof(controllerName)); - var formAction = UmbracoContext.Current.OriginalRequestUrl.PathAndQuery; + var formAction = Current.UmbracoContext.OriginalRequestUrl.PathAndQuery; return html.RenderForm(formAction, method, htmlAttributes, controllerName, action, area, additionalRouteVals); } diff --git a/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs b/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs index d1f3071e95..44ee77507b 100644 --- a/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs +++ b/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs @@ -6,6 +6,7 @@ using System.Web.WebPages; using Umbraco.Web.Mvc; using Umbraco.Core; using Umbraco.Core.Models.PublishedContent; +using Umbraco.Web.Composing; namespace Umbraco.Web.Macros { @@ -28,9 +29,9 @@ namespace Umbraco.Web.Macros _getUmbracoContext = () => { - if (UmbracoContext.Current == null) + if (Current.UmbracoContext == null) throw new InvalidOperationException($"The {GetType()} cannot execute with a null UmbracoContext.Current reference."); - return UmbracoContext.Current; + return Current.UmbracoContext; }; } diff --git a/src/Umbraco.Web/Models/Mapping/ActionButtonsResolver.cs b/src/Umbraco.Web/Models/Mapping/ActionButtonsResolver.cs index c2f7abd487..9c5a4a0b88 100644 --- a/src/Umbraco.Web/Models/Mapping/ActionButtonsResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/ActionButtonsResolver.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Umbraco.Core.Models; using Umbraco.Core.Services; +using Umbraco.Web.Composing; namespace Umbraco.Web.Models.Mapping { @@ -23,7 +24,7 @@ namespace Umbraco.Web.Models.Mapping public IEnumerable Resolve(IContent source) { //cannot check permissions without a context - if (UmbracoContext.Current == null) + if (Current.UmbracoContext == null) return Enumerable.Empty(); string path; @@ -38,7 +39,7 @@ namespace Umbraco.Web.Models.Mapping // TODO: This is certainly not ideal usage here - perhaps the best way to deal with this in the future is // with the IUmbracoContextAccessor. In the meantime, if used outside of a web app this will throw a null // reference exception :( - return UserService.GetPermissionsForPath(UmbracoContext.Current.Security.CurrentUser, path).GetAllPermissions(); + return UserService.GetPermissionsForPath(Current.UmbracoContext.Security.CurrentUser, path).GetAllPermissions(); } } } diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeBasicResolver.cs b/src/Umbraco.Web/Models/Mapping/ContentTypeBasicResolver.cs index aa97b25260..8b5f3d4296 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeBasicResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentTypeBasicResolver.cs @@ -5,6 +5,7 @@ using AutoMapper; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Services; +using Umbraco.Web.Composing; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.Models.Mapping @@ -27,8 +28,8 @@ namespace Umbraco.Web.Models.Mapping { // TODO: We can resolve the UmbracoContext from the IValueResolver options! // OMG - if (HttpContext.Current != null && UmbracoContext.Current != null && UmbracoContext.Current.Security.CurrentUser != null - && UmbracoContext.Current.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings))) + if (HttpContext.Current != null && Current.UmbracoContext != null && Current.UmbracoContext.Security.CurrentUser != null + && Current.UmbracoContext.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings))) { var contentType = _contentTypeBaseServiceProvider.GetContentTypeOf(source); var contentTypeBasic = Mapper.Map(contentType); diff --git a/src/Umbraco.Web/Mvc/EnsurePublishedContentRequestAttribute.cs b/src/Umbraco.Web/Mvc/EnsurePublishedContentRequestAttribute.cs index c6fc1d907f..3eaad90ca4 100644 --- a/src/Umbraco.Web/Mvc/EnsurePublishedContentRequestAttribute.cs +++ b/src/Umbraco.Web/Mvc/EnsurePublishedContentRequestAttribute.cs @@ -69,7 +69,7 @@ namespace Umbraco.Web.Mvc /// /// Exposes the UmbracoContext /// - protected UmbracoContext UmbracoContext => _umbracoContext ?? (_umbracoContext = UmbracoContext.Current); + protected UmbracoContext UmbracoContext => _umbracoContext ?? (_umbracoContext = Current.UmbracoContext); // TODO: try lazy property injection? private IPublishedRouter PublishedRouter => Core.Composing.Current.Factory.GetInstance(); @@ -84,13 +84,13 @@ namespace Umbraco.Web.Mvc base.OnActionExecuted(filterContext); // First we need to check if the published content request has been set, if it has we're going to ignore this and not actually do anything - if (UmbracoContext.Current.PublishedRequest != null) + if (Current.UmbracoContext.PublishedRequest != null) { return; } - UmbracoContext.Current.PublishedRequest = PublishedRouter.CreateRequest(UmbracoContext.Current); - ConfigurePublishedContentRequest(UmbracoContext.Current.PublishedRequest, filterContext); + Current.UmbracoContext.PublishedRequest = PublishedRouter.CreateRequest(Current.UmbracoContext); + ConfigurePublishedContentRequest(Current.UmbracoContext.PublishedRequest, filterContext); } /// diff --git a/src/Umbraco.Web/Mvc/RedirectToUmbracoPageResult.cs b/src/Umbraco.Web/Mvc/RedirectToUmbracoPageResult.cs index 8dd9dafec0..6e5c12ee64 100644 --- a/src/Umbraco.Web/Mvc/RedirectToUmbracoPageResult.cs +++ b/src/Umbraco.Web/Mvc/RedirectToUmbracoPageResult.cs @@ -6,6 +6,7 @@ using System.Web.Mvc; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; +using Umbraco.Web.Composing; namespace Umbraco.Web.Mvc { @@ -55,7 +56,7 @@ namespace Umbraco.Web.Mvc if (_publishedContent != null) return _publishedContent; //need to get the URL for the page - _publishedContent = UmbracoContext.Current.ContentCache.GetById(_pageId); + _publishedContent = Current.UmbracoContext.ContentCache.GetById(_pageId); return _publishedContent; } @@ -66,7 +67,7 @@ namespace Umbraco.Web.Mvc /// /// public RedirectToUmbracoPageResult(int pageId) - : this(pageId, UmbracoContext.Current) + : this(pageId, Current.UmbracoContext) { } @@ -76,7 +77,7 @@ namespace Umbraco.Web.Mvc /// /// public RedirectToUmbracoPageResult(int pageId, NameValueCollection queryStringValues) - : this(pageId, queryStringValues, UmbracoContext.Current) + : this(pageId, queryStringValues, Current.UmbracoContext) { } @@ -86,7 +87,7 @@ namespace Umbraco.Web.Mvc /// /// public RedirectToUmbracoPageResult(int pageId, string queryString) - : this(pageId, queryString, UmbracoContext.Current) + : this(pageId, queryString, Current.UmbracoContext) { } @@ -95,7 +96,7 @@ namespace Umbraco.Web.Mvc /// /// public RedirectToUmbracoPageResult(IPublishedContent publishedContent) - : this(publishedContent, UmbracoContext.Current) + : this(publishedContent, Current.UmbracoContext) { } @@ -105,7 +106,7 @@ namespace Umbraco.Web.Mvc /// /// public RedirectToUmbracoPageResult(IPublishedContent publishedContent, NameValueCollection queryStringValues) - : this(publishedContent, queryStringValues, UmbracoContext.Current) + : this(publishedContent, queryStringValues, Current.UmbracoContext) { } @@ -115,7 +116,7 @@ namespace Umbraco.Web.Mvc /// /// public RedirectToUmbracoPageResult(IPublishedContent publishedContent, string queryString) - : this(publishedContent, queryString, UmbracoContext.Current) + : this(publishedContent, queryString, Current.UmbracoContext) { } diff --git a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs index 854b59787f..68359252d4 100644 --- a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs +++ b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs @@ -206,7 +206,7 @@ namespace Umbraco.Web.Mvc // filter / add preview banner if (Response.ContentType.InvariantEquals("text/html")) // ASP.NET default value { - if (UmbracoContext.Current.IsDebug || UmbracoContext.Current.InPreviewMode) + if (Current.UmbracoContext.IsDebug || Current.UmbracoContext.InPreviewMode) { var text = value.ToString(); var pos = text.IndexOf("", StringComparison.InvariantCultureIgnoreCase); @@ -215,13 +215,13 @@ namespace Umbraco.Web.Mvc { string markupToInject; - if (UmbracoContext.Current.InPreviewMode) + if (Current.UmbracoContext.InPreviewMode) { // creating previewBadge markup markupToInject = string.Format(Current.Configs.Settings().Content.PreviewBadge, IOHelper.ResolveUrl(SystemDirectories.Umbraco), - Server.UrlEncode(UmbracoContext.Current.HttpContext.Request.Url?.PathAndQuery)); + Server.UrlEncode(Current.UmbracoContext.HttpContext.Request.Url?.PathAndQuery)); } else { diff --git a/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs b/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs index 1af434e94e..6f5dcab45f 100644 --- a/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs @@ -40,7 +40,7 @@ namespace Umbraco.Web.Mvc /// protected virtual UmbracoContext GetUmbracoContext(RequestContext requestContext) { - return UmbracoContext.Current; + return Composing.Current.UmbracoContext; } public IHttpHandler GetHttpHandler(RequestContext requestContext) diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs index c96e9ff9a3..cb9709157f 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs @@ -4,6 +4,7 @@ using HeyRed.MarkdownSharp; using Umbraco.Core; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; +using Umbraco.Web.Composing; using Umbraco.Web.Templates; namespace Umbraco.Web.PropertyEditors.ValueConverters @@ -26,7 +27,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters var sourceString = source.ToString(); // ensures string is parsed for {localLink} and urls are resolved correctly - sourceString = TemplateUtilities.ParseInternalLinks(sourceString, preview, UmbracoContext.Current); + sourceString = TemplateUtilities.ParseInternalLinks(sourceString, preview, Current.UmbracoContext); sourceString = TemplateUtilities.ResolveUrlsFromTextString(sourceString); return sourceString; diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs index 3abdc0702a..b4c7f99a75 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs @@ -2,6 +2,7 @@ using Umbraco.Core; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; +using Umbraco.Web.Composing; using Umbraco.Web.PublishedCache; using Umbraco.Web.Security; @@ -44,7 +45,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters if (source == null) return null; - if (UmbracoContext.Current != null) + if (Current.UmbracoContext != null) { IPublishedContent member; if (source is int id) diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs index beb22bb57e..a210aa62c6 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.ValueConverters; using Umbraco.Core.Services; +using Umbraco.Web.Composing; using Umbraco.Web.PublishedCache; namespace Umbraco.Web.PropertyEditors.ValueConverters @@ -67,7 +68,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters } // TODO: Inject an UmbracoHelper and create a GetUmbracoHelper method based on either injected or singleton - if (UmbracoContext.Current != null) + if (Current.UmbracoContext != null) { if (propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.MultiNodeTreePicker)) { diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs index e636369c74..79bfa0aeaa 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/RteMacroRenderingValueConverter.cs @@ -9,6 +9,7 @@ using System.Linq; using HtmlAgilityPack; using Umbraco.Core.Cache; using Umbraco.Core.Services; +using Umbraco.Web.Composing; using Umbraco.Web.Macros; namespace Umbraco.Web.PropertyEditors.ValueConverters @@ -72,7 +73,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters var sourceString = source.ToString(); // ensures string is parsed for {localLink} and urls are resolved correctly - sourceString = TemplateUtilities.ParseInternalLinks(sourceString, preview, UmbracoContext.Current); + sourceString = TemplateUtilities.ParseInternalLinks(sourceString, preview, Current.UmbracoContext); sourceString = TemplateUtilities.ResolveUrlsFromTextString(sourceString); // ensure string is parsed for macros and macros are executed correctly diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs index 5fe731ffb3..2d5c322f58 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs @@ -3,6 +3,7 @@ using System.Linq; using Umbraco.Core; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; +using Umbraco.Web.Composing; using Umbraco.Web.Templates; namespace Umbraco.Web.PropertyEditors.ValueConverters @@ -31,7 +32,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters var sourceString = source.ToString(); // ensures string is parsed for {localLink} and urls are resolved correctly - sourceString = TemplateUtilities.ParseInternalLinks(sourceString, preview, UmbracoContext.Current); + sourceString = TemplateUtilities.ParseInternalLinks(sourceString, preview, Current.UmbracoContext); sourceString = TemplateUtilities.ResolveUrlsFromTextString(sourceString); return sourceString; diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index 5d47d7b6a5..c77594eabe 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -46,11 +46,11 @@ namespace Umbraco.Web switch (content.ItemType) { case PublishedItemType.Content: - if (UmbracoContext.Current == null) - throw new InvalidOperationException("Cannot resolve a Url for a content item when UmbracoContext.Current is null."); - if (UmbracoContext.Current.UrlProvider == null) - throw new InvalidOperationException("Cannot resolve a Url for a content item when UmbracoContext.Current.UrlProvider is null."); - return UmbracoContext.Current.UrlProvider.GetUrl(content.Id, true); + if (Current.UmbracoContext == null) + throw new InvalidOperationException("Cannot resolve a Url for a content item when Current.UmbracoContext is null."); + if (Current.UmbracoContext.UrlProvider == null) + throw new InvalidOperationException("Cannot resolve a Url for a content item when Current.UmbracoContext.UrlProvider is null."); + return Current.UmbracoContext.UrlProvider.GetUrl(content.Id, true); case PublishedItemType.Media: throw new NotSupportedException("AbsoluteUrl is not supported for media types."); default: @@ -267,7 +267,7 @@ namespace Umbraco.Web .And() .ManagedQuery(term); - return query.Execute().ToPublishedSearchResults(UmbracoContext.Current.ContentCache); + return query.Execute().ToPublishedSearchResults(Current.UmbracoContext.ContentCache); } public static IEnumerable SearchChildren(this IPublishedContent content, string term, string indexName = null) @@ -288,7 +288,7 @@ namespace Umbraco.Web .And() .ManagedQuery(term); - return query.Execute().ToPublishedSearchResults(UmbracoContext.Current.ContentCache); + return query.Execute().ToPublishedSearchResults(Current.UmbracoContext.ContentCache); } #endregion diff --git a/src/Umbraco.Web/Routing/PublishedContentNotFoundHandler.cs b/src/Umbraco.Web/Routing/PublishedContentNotFoundHandler.cs index c577ec82cf..ae8da1fc6c 100644 --- a/src/Umbraco.Web/Routing/PublishedContentNotFoundHandler.cs +++ b/src/Umbraco.Web/Routing/PublishedContentNotFoundHandler.cs @@ -1,4 +1,5 @@ using System.Web; +using Umbraco.Web.Composing; namespace Umbraco.Web.Routing { @@ -28,7 +29,7 @@ namespace Umbraco.Web.Routing response.Clear(); - var frequest = UmbracoContext.Current.PublishedRequest; + var frequest = Current.UmbracoContext.PublishedRequest; var reason = "Cannot render the page at url '{0}'."; if (frequest.HasPublishedContent == false) reason = "No umbraco document matches the url '{0}'."; @@ -37,7 +38,7 @@ namespace Umbraco.Web.Routing response.Write("

Page not found

"); response.Write("

"); - response.Write(string.Format(reason, HttpUtility.HtmlEncode(UmbracoContext.Current.OriginalRequestUrl.PathAndQuery))); + response.Write(string.Format(reason, HttpUtility.HtmlEncode(Current.UmbracoContext.OriginalRequestUrl.PathAndQuery))); response.Write("

"); if (string.IsNullOrWhiteSpace(_message) == false) response.Write("

" + _message + "

"); diff --git a/src/Umbraco.Web/Routing/RedirectTrackingComponent.cs b/src/Umbraco.Web/Routing/RedirectTrackingComponent.cs index acbd022f2e..690bbb58be 100644 --- a/src/Umbraco.Web/Routing/RedirectTrackingComponent.cs +++ b/src/Umbraco.Web/Routing/RedirectTrackingComponent.cs @@ -38,9 +38,9 @@ namespace Umbraco.Web.Routing { get { - var oldRoutes = (Dictionary) UmbracoContext.Current.HttpContext.Items[ContextKey3]; + var oldRoutes = (Dictionary) Current.UmbracoContext.HttpContext.Items[ContextKey3]; if (oldRoutes == null) - UmbracoContext.Current.HttpContext.Items[ContextKey3] = oldRoutes = new Dictionary(); + Current.UmbracoContext.HttpContext.Items[ContextKey3] = oldRoutes = new Dictionary(); return oldRoutes; } } @@ -58,27 +58,27 @@ namespace Umbraco.Web.Routing private static bool LockedEvents { - get => Moving && UmbracoContext.Current.HttpContext.Items[ContextKey2] != null; + get => Moving && Current.UmbracoContext.HttpContext.Items[ContextKey2] != null; set { if (Moving && value) - UmbracoContext.Current.HttpContext.Items[ContextKey2] = true; + Current.UmbracoContext.HttpContext.Items[ContextKey2] = true; else - UmbracoContext.Current.HttpContext.Items.Remove(ContextKey2); + Current.UmbracoContext.HttpContext.Items.Remove(ContextKey2); } } private static bool Moving { - get => UmbracoContext.Current.HttpContext.Items[ContextKey1] != null; + get => Current.UmbracoContext.HttpContext.Items[ContextKey1] != null; set { if (value) - UmbracoContext.Current.HttpContext.Items[ContextKey1] = true; + Current.UmbracoContext.HttpContext.Items[ContextKey1] = true; else { - UmbracoContext.Current.HttpContext.Items.Remove(ContextKey1); - UmbracoContext.Current.HttpContext.Items.Remove(ContextKey2); + Current.UmbracoContext.HttpContext.Items.Remove(ContextKey1); + Current.UmbracoContext.HttpContext.Items.Remove(ContextKey2); } } } @@ -164,7 +164,7 @@ namespace Umbraco.Web.Routing { if (LockedEvents) return; - var contentCache = UmbracoContext.Current.ContentCache; + var contentCache = Current.UmbracoContext.ContentCache; foreach (var entity in args.PublishedEntities) { var entityContent = contentCache.GetById(entity.Id); @@ -205,7 +205,7 @@ namespace Umbraco.Web.Routing private static void CreateRedirect(int contentId, string culture, Guid contentKey, string oldRoute) { - var contentCache = UmbracoContext.Current.ContentCache; + var contentCache = Current.UmbracoContext.ContentCache; var newRoute = contentCache.GetRouteById(contentId, culture); if (IsNotRoute(newRoute) || oldRoute == newRoute) return; var redirectUrlService = Current.Services.RedirectUrlService; diff --git a/src/Umbraco.Web/Routing/UrlProvider.cs b/src/Umbraco.Web/Routing/UrlProvider.cs index 4dd4820d26..da64d46046 100644 --- a/src/Umbraco.Web/Routing/UrlProvider.cs +++ b/src/Umbraco.Web/Routing/UrlProvider.cs @@ -6,6 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; +using Umbraco.Web.Composing; namespace Umbraco.Web.Routing { @@ -210,7 +211,7 @@ namespace Umbraco.Web.Routing var provider = _urlProviders.OfType().FirstOrDefault(); var url = provider == null ? route // what else? - : provider.GetUrlFromRoute(route, UmbracoContext.Current, id, _umbracoContext.CleanedUmbracoUrl, Mode, culture)?.Text; + : provider.GetUrlFromRoute(route, Current.UmbracoContext, id, _umbracoContext.CleanedUmbracoUrl, Mode, culture)?.Text; return url ?? "#"; } diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index a1b443c3ee..fd6edeeb8a 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -174,12 +174,6 @@ namespace Umbraco.Web #endregion - /// - /// Gets the current Umbraco Context. - /// - // note: obsolete, use Current.UmbracoContext... then obsolete Current too, and inject! - public static UmbracoContext Current => Composing.Current.UmbracoContext; - /// /// This is used internally for performance calculations, the ObjectCreated DateTime is set as soon as this /// object is instantiated which in the web site is created during the BeginRequest phase. @@ -281,7 +275,7 @@ namespace Umbraco.Web || string.IsNullOrEmpty(request["umbdebug"]) == false); } } - + /// /// Determines whether the current user is in a preview mode and browsing the site (ie. not in the admin UI) /// diff --git a/src/Umbraco.Web/UmbracoInjectedModule.cs b/src/Umbraco.Web/UmbracoInjectedModule.cs index ba1a384484..1898309cf0 100644 --- a/src/Umbraco.Web/UmbracoInjectedModule.cs +++ b/src/Umbraco.Web/UmbracoInjectedModule.cs @@ -124,10 +124,10 @@ namespace Umbraco.Web if (httpContext.Request.Url.IsClientSideRequest()) return; - if (UmbracoContext.Current == null) - throw new InvalidOperationException("The UmbracoContext.Current is null, ProcessRequest cannot proceed unless there is a current UmbracoContext"); + if (Current.UmbracoContext == null) + throw new InvalidOperationException("The Current.UmbracoContext is null, ProcessRequest cannot proceed unless there is a current UmbracoContext"); - var umbracoContext = UmbracoContext.Current; + var umbracoContext = Current.UmbracoContext; // re-write for the default back office path if (httpContext.Request.Url.IsDefaultBackOfficeRequest(_globalSettings)) @@ -491,14 +491,14 @@ namespace Umbraco.Web { var httpContext = ((HttpApplication) sender).Context; - if (UmbracoContext.Current != null && UmbracoContext.Current.IsFrontEndUmbracoRequest) + if (Current.UmbracoContext != null && Current.UmbracoContext.IsFrontEndUmbracoRequest) { LogHttpRequest.TryGetCurrentHttpRequestId(out var httpRequestId); - _logger.Verbose("End Request [{HttpRequestId}]: {RequestUrl} ({RequestDuration}ms)", httpRequestId, httpContext.Request.Url, DateTime.Now.Subtract(UmbracoContext.Current.ObjectCreated).TotalMilliseconds); + _logger.Verbose("End Request [{HttpRequestId}]: {RequestUrl} ({RequestDuration}ms)", httpRequestId, httpContext.Request.Url, DateTime.Now.Subtract(Current.UmbracoContext.ObjectCreated).TotalMilliseconds); } - UmbracoModule.OnEndRequest(this, new UmbracoRequestEventArgs(UmbracoContext.Current, new HttpContextWrapper(httpContext))); + UmbracoModule.OnEndRequest(this, new UmbracoRequestEventArgs(Current.UmbracoContext, new HttpContextWrapper(httpContext))); DisposeHttpContextItems(httpContext); }; diff --git a/src/Umbraco.Web/UrlHelperRenderExtensions.cs b/src/Umbraco.Web/UrlHelperRenderExtensions.cs index 2835bc02dc..cc5000bb19 100644 --- a/src/Umbraco.Web/UrlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/UrlHelperRenderExtensions.cs @@ -296,7 +296,7 @@ namespace Umbraco.Web var encryptedRoute = UmbracoHelper.CreateEncryptedRouteString(controllerName, action, area, additionalRouteVals); - var result = UmbracoContext.Current.OriginalRequestUrl.AbsolutePath.EnsureEndsWith('?') + "ufprt=" + encryptedRoute; + var result = Current.UmbracoContext.OriginalRequestUrl.AbsolutePath.EnsureEndsWith('?') + "ufprt=" + encryptedRoute; return result; } @@ -339,7 +339,7 @@ namespace Umbraco.Web var encryptedRoute = UmbracoHelper.CreateEncryptedRouteString(metaData.ControllerName, action, area, additionalRouteVals); - var result = UmbracoContext.Current.OriginalRequestUrl.AbsolutePath.EnsureEndsWith('?') + "ufprt=" + encryptedRoute; + var result = Current.UmbracoContext.OriginalRequestUrl.AbsolutePath.EnsureEndsWith('?') + "ufprt=" + encryptedRoute; return result; } diff --git a/src/Umbraco.Web/WebApi/Filters/AppendCurrentEventMessagesAttribute.cs b/src/Umbraco.Web/WebApi/Filters/AppendCurrentEventMessagesAttribute.cs index 779a559a16..8669533e78 100644 --- a/src/Umbraco.Web/WebApi/Filters/AppendCurrentEventMessagesAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/AppendCurrentEventMessagesAttribute.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.WebApi.Filters { if (context.Response == null) return; if (context.Request.Method == HttpMethod.Get) return; - if (UmbracoContext.Current == null) return; + if (Current.UmbracoContext == null) return; var obj = context.Response.Content as ObjectContent; if (obj == null) return; diff --git a/src/Umbraco.Web/WebApi/Filters/AppendUserModifiedHeaderAttribute.cs b/src/Umbraco.Web/WebApi/Filters/AppendUserModifiedHeaderAttribute.cs index 3b2ee30aa0..5ac8d886f0 100644 --- a/src/Umbraco.Web/WebApi/Filters/AppendUserModifiedHeaderAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/AppendUserModifiedHeaderAttribute.cs @@ -2,6 +2,7 @@ using System.Web.Http.Filters; using Umbraco.Core; using Umbraco.Core.Models; +using Umbraco.Web.Composing; namespace Umbraco.Web.WebApi.Filters { @@ -53,7 +54,7 @@ namespace Umbraco.Web.WebApi.Filters throw new InvalidOperationException("No argument found for the current action with the name: " + _userIdParameter); } - var user = UmbracoContext.Current.Security.CurrentUser; + var user = Current.UmbracoContext.Security.CurrentUser; if (user == null) return; var userId = GetUserIdFromParameter(actionContext.ActionArguments[_userIdParameter]); diff --git a/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForContentAttribute.cs b/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForContentAttribute.cs index ae42d54787..efee045890 100644 --- a/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForContentAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForContentAttribute.cs @@ -61,7 +61,7 @@ namespace Umbraco.Web.WebApi.Filters public override void OnActionExecuting(HttpActionContext actionContext) { - if (UmbracoContext.Current.Security.CurrentUser == null) + if (Current.UmbracoContext.Security.CurrentUser == null) { //not logged in throw new HttpResponseException(System.Net.HttpStatusCode.Unauthorized); diff --git a/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs b/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs index 026b43a01b..24bf2ea9a8 100644 --- a/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs @@ -80,7 +80,7 @@ namespace Umbraco.Web.WebApi.Filters public override void OnActionExecuting(HttpActionContext actionContext) { - if (UmbracoContext.Current.Security.CurrentUser == null) + if (Current.UmbracoContext.Security.CurrentUser == null) { throw new HttpResponseException(System.Net.HttpStatusCode.Unauthorized); } @@ -118,7 +118,7 @@ namespace Umbraco.Web.WebApi.Filters if (MediaController.CheckPermissions( actionContext.Request.Properties, - UmbracoContext.Current.Security.CurrentUser, + Current.UmbracoContext.Security.CurrentUser, Current.Services.MediaService, Current.Services.EntityService, nodeId)) diff --git a/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingMediaAttribute.cs b/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingMediaAttribute.cs index 4a4c5b98a0..21dc60e6cc 100644 --- a/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingMediaAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingMediaAttribute.cs @@ -48,7 +48,7 @@ namespace Umbraco.Web.WebApi.Filters { if (actionExecutedContext.Response == null) return; - var user = UmbracoContext.Current.Security.CurrentUser; + var user = Composing.Current.UmbracoContext.Security.CurrentUser; if (user == null) return; var objectContent = actionExecutedContext.Response.Content as ObjectContent; diff --git a/src/Umbraco.Web/WebApi/Filters/OutgoingEditorModelEventAttribute.cs b/src/Umbraco.Web/WebApi/Filters/OutgoingEditorModelEventAttribute.cs index 8410891a5d..e2a6f155d0 100644 --- a/src/Umbraco.Web/WebApi/Filters/OutgoingEditorModelEventAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/OutgoingEditorModelEventAttribute.cs @@ -2,6 +2,7 @@ using System.Net.Http; using System.Web.Http.Filters; using Umbraco.Core; +using Umbraco.Web.Composing; using Umbraco.Web.Editors; using Umbraco.Web.Models.ContentEditing; @@ -16,7 +17,7 @@ namespace Umbraco.Web.WebApi.Filters { if (actionExecutedContext.Response == null) return; - var user = UmbracoContext.Current.Security.CurrentUser; + var user = Current.UmbracoContext.Security.CurrentUser; if (user == null) return; if (actionExecutedContext.Response.Content is ObjectContent objectContent) @@ -27,7 +28,7 @@ namespace Umbraco.Web.WebApi.Filters { var args = new EditorModelEventArgs( model, - UmbracoContext.Current); + Current.UmbracoContext); EditorModelEventManager.EmitEvent(actionExecutedContext, args); objectContent.Value = args.Model; }