From c335a8dbb5fcf087e18a622880b302775c5d7d03 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Sun, 9 Feb 2020 18:53:37 +0100 Subject: [PATCH] Introduced interface on UmbracoContext --- .../PublishedContentCacheTests.cs | 2 +- .../Composing/TypeFinderTests.cs | 2 +- .../Composing/TypeLoaderTests.cs | 4 +- .../UmbracoContextCache.cs | 4 +- .../PublishedContentExtensionTests.cs | 2 +- .../PublishedContentSnapshotTestBase.cs | 2 +- .../PublishedContent/PublishedMediaTests.cs | 2 +- .../Scoping/ScopedNuCacheTests.cs | 2 +- .../Templates/HtmlImageSourceParserTests.cs | 2 +- .../Templates/HtmlLocalLinkParserTests.cs | 4 +- .../TestControllerActivatorBase.cs | 2 +- .../TestHelpers/TestObjects-Mocks.cs | 2 +- .../TestHelpers/TestWithDatabaseBase.cs | 2 +- .../Accessors/TestUmbracoContextAccessor.cs | 4 +- .../Testing/TestingTests/MockTests.cs | 2 +- .../Web/Mvc/UmbracoViewPageTests.cs | 2 +- src/Umbraco.Web/Composing/Current.cs | 2 +- .../Editors/EditorModelEventArgs.cs | 6 +- .../UserGroupAuthorizationAttribute.cs | 2 +- .../HttpContextUmbracoContextAccessor.cs | 4 +- .../HybridUmbracoContextAccessor.cs | 4 +- src/Umbraco.Web/IUmbracoContext.cs | 135 ++++++++++++++++++ src/Umbraco.Web/IUmbracoContextAccessor.cs | 2 +- src/Umbraco.Web/IUmbracoContextFactory.cs | 6 +- .../Install/HttpInstallAuthorizeAttribute.cs | 2 +- .../Install/InstallAuthorizeAttribute.cs | 2 +- .../Macros/PartialViewMacroEngine.cs | 4 +- .../Mapping/RedirectUrlMapDefinition.cs | 2 +- .../Mvc/ControllerContextExtensions.cs | 4 +- .../EnsurePublishedContentRequestAttribute.cs | 2 +- src/Umbraco.Web/Mvc/PluginController.cs | 2 +- .../Mvc/RedirectToUmbracoUrlResult.cs | 4 +- src/Umbraco.Web/Mvc/RenderMvcController.cs | 2 +- src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 6 +- .../Mvc/UmbracoAuthorizeAttribute.cs | 6 +- src/Umbraco.Web/Mvc/UmbracoController.cs | 2 +- .../Mvc/UmbracoViewPageOfTModel.cs | 4 +- .../Mvc/UmbracoVirtualNodeByIdRouteHandler.cs | 4 +- .../UmbracoVirtualNodeByUdiRouteHandler.cs | 4 +- .../Mvc/UmbracoVirtualNodeRouteHandler.cs | 4 +- src/Umbraco.Web/PublishedContentExtensions.cs | 2 +- src/Umbraco.Web/Routing/AliasUrlProvider.cs | 4 +- .../Routing/DefaultMediaUrlProvider.cs | 2 +- src/Umbraco.Web/Routing/DefaultUrlProvider.cs | 6 +- src/Umbraco.Web/Routing/DomainUtilities.cs | 2 +- src/Umbraco.Web/Routing/IMediaUrlProvider.cs | 2 +- src/Umbraco.Web/Routing/IPublishedRouter.cs | 2 +- src/Umbraco.Web/Routing/IUrlProvider.cs | 4 +- src/Umbraco.Web/Routing/PublishedRequest.cs | 4 +- src/Umbraco.Web/Routing/PublishedRouter.cs | 2 +- .../Routing/RoutableAttemptEventArgs.cs | 2 +- .../Routing/UmbracoRequestEventArgs.cs | 4 +- src/Umbraco.Web/Routing/UrlProvider.cs | 6 +- .../Routing/UrlProviderExtensions.cs | 6 +- src/Umbraco.Web/Runtime/WebInitialComposer.cs | 4 +- src/Umbraco.Web/Search/UmbracoTreeSearcher.cs | 4 +- .../Security/ExternalSignInAutoLinkOptions.cs | 6 +- .../IUmbracoBackOfficeTwoFactorOptions.cs | 2 +- src/Umbraco.Web/Umbraco.Web.csproj | 3 +- src/Umbraco.Web/UmbracoContext.cs | 29 ++-- src/Umbraco.Web/UmbracoContextFactory.cs | 4 +- src/Umbraco.Web/UmbracoContextReference.cs | 4 +- src/Umbraco.Web/UmbracoInjectedModule.cs | 4 +- src/Umbraco.Web/UmbracoWebService.cs | 2 +- .../WebApi/UmbracoApiControllerBase.cs | 2 +- .../WebApi/UmbracoAuthorizeAttribute.cs | 6 +- 66 files changed, 252 insertions(+), 121 deletions(-) create mode 100644 src/Umbraco.Web/IUmbracoContext.cs diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs index 7ef4495ad2..36f0c6f6b3 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs @@ -23,7 +23,7 @@ namespace Umbraco.Tests.Cache.PublishedCache public class PublishContentCacheTests : BaseWebTest { private FakeHttpContextFactory _httpContextFactory; - private UmbracoContext _umbracoContext; + private IUmbracoContext _umbracoContext; private IPublishedContentCache _cache; private XmlDocument _xml; diff --git a/src/Umbraco.Tests/Composing/TypeFinderTests.cs b/src/Umbraco.Tests/Composing/TypeFinderTests.cs index 5fe4c241d6..a2ed0690e5 100644 --- a/src/Umbraco.Tests/Composing/TypeFinderTests.cs +++ b/src/Umbraco.Tests/Composing/TypeFinderTests.cs @@ -69,7 +69,7 @@ namespace Umbraco.Tests.Composing var typesFound = typeFinder.FindClassesWithAttribute(_assemblies); Assert.AreEqual(0, typesFound.Count()); // 0 classes in _assemblies are marked with [Tree] - typesFound = typeFinder.FindClassesWithAttribute(new[] { typeof (UmbracoContext).Assembly }); + typesFound = typeFinder.FindClassesWithAttribute(new[] { typeof (IUmbracoContext).Assembly }); Assert.AreEqual(22, typesFound.Count()); // + classes in Umbraco.Web are marked with [Tree] } diff --git a/src/Umbraco.Tests/Composing/TypeLoaderTests.cs b/src/Umbraco.Tests/Composing/TypeLoaderTests.cs index 21ce6aa8f8..641d4814ec 100644 --- a/src/Umbraco.Tests/Composing/TypeLoaderTests.cs +++ b/src/Umbraco.Tests/Composing/TypeLoaderTests.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Composing //typeof(TabPage).Assembly, typeof(System.Web.Mvc.ActionResult).Assembly, typeof(TypeFinder).Assembly, - typeof(UmbracoContext).Assembly, + typeof(IUmbracoContext).Assembly, typeof(CheckBoxListPropertyEditor).Assembly }); @@ -196,7 +196,7 @@ AnotherContentFinder [Test] public void Create_Cached_Plugin_File() { - var types = new[] { typeof(TypeLoader), typeof(TypeLoaderTests), typeof(UmbracoContext) }; + var types = new[] { typeof(TypeLoader), typeof(TypeLoaderTests), typeof(IUmbracoContext) }; var typeList1 = new TypeLoader.TypeList(typeof(object), null); foreach (var type in types) typeList1.Add(type); diff --git a/src/Umbraco.Tests/LegacyXmlPublishedCache/UmbracoContextCache.cs b/src/Umbraco.Tests/LegacyXmlPublishedCache/UmbracoContextCache.cs index 5d48e9eae3..e967a1ea12 100644 --- a/src/Umbraco.Tests/LegacyXmlPublishedCache/UmbracoContextCache.cs +++ b/src/Umbraco.Tests/LegacyXmlPublishedCache/UmbracoContextCache.cs @@ -6,8 +6,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache { static class UmbracoContextCache { - static readonly ConditionalWeakTable> Caches - = new ConditionalWeakTable>(); + static readonly ConditionalWeakTable> Caches + = new ConditionalWeakTable>(); public static ConcurrentDictionary Current { diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs index d1c39e1e31..fdf9863c78 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentExtensionTests.cs @@ -12,7 +12,7 @@ namespace Umbraco.Tests.PublishedContent [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] public class PublishedContentExtensionTests : PublishedContentTestBase { - private UmbracoContext _ctx; + private IUmbracoContext _ctx; private string _xmlContent = ""; private bool _createContentTypes = true; private Dictionary _contentTypes; diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs index 8698eb18d7..89995ebf73 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs @@ -56,7 +56,7 @@ namespace Umbraco.Tests.PublishedContent .ToList()); } - private UmbracoContext GetUmbracoContext() + private IUmbracoContext GetUmbracoContext() { RouteData routeData = null; diff --git a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs index 94e85dd011..89b8de8085 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs @@ -68,7 +68,7 @@ namespace Umbraco.Tests.PublishedContent /// /// /// - internal IPublishedContent GetNode(int id, UmbracoContext umbracoContext) + internal IPublishedContent GetNode(int id, IUmbracoContext umbracoContext) { var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null, null, null, null, HostingEnvironment), ServiceContext.MediaService, ServiceContext.UserService, new DictionaryAppCache(), ContentTypesCache, diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index 9e351ff3c9..d4d00f60ef 100644 --- a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs @@ -111,7 +111,7 @@ namespace Umbraco.Tests.Scoping filePermissionHelper); } - protected UmbracoContext GetUmbracoContextNu(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable urlProviders = null) + protected IUmbracoContext GetUmbracoContextNu(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable urlProviders = null) { // ensure we have a PublishedSnapshotService var service = PublishedSnapshotService as PublishedSnapshotService; diff --git a/src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs b/src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs index d39586890a..141a0a916d 100644 --- a/src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs +++ b/src/Umbraco.Tests/Templates/HtmlImageSourceParserTests.cs @@ -69,7 +69,7 @@ namespace Umbraco.Tests.Templates var media = new Mock(); media.Setup(x => x.ContentType).Returns(mediaType); var mediaUrlProvider = new Mock(); - mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(UrlInfo.Url("/media/1001/my-image.jpg")); var umbracoContextAccessor = new TestUmbracoContextAccessor(); diff --git a/src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs b/src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs index 17f0471252..5560e39152 100644 --- a/src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs +++ b/src/Umbraco.Tests/Templates/HtmlLocalLinkParserTests.cs @@ -52,7 +52,7 @@ namespace Umbraco.Tests.Templates //setup a mock url provider which we'll use for testing var contentUrlProvider = new Mock(); contentUrlProvider - .Setup(x => x.GetUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Setup(x => x.GetUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(UrlInfo.Url("/my-test-url")); var contentType = new PublishedContentType(666, "alias", PublishedItemType.Content, Enumerable.Empty(), Enumerable.Empty(), ContentVariation.Nothing); var publishedContent = new Mock(); @@ -63,7 +63,7 @@ namespace Umbraco.Tests.Templates var media = new Mock(); media.Setup(x => x.ContentType).Returns(mediaType); var mediaUrlProvider = new Mock(); - mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(UrlInfo.Url("/media/1001/my-image.jpg")); var umbracoContextAccessor = new TestUmbracoContextAccessor(); diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs index 17e1918d05..c0279e1204 100644 --- a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs +++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs @@ -150,7 +150,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting umbracoContextAccessor.UmbracoContext = umbCtx; var urlHelper = new Mock(); - urlHelper.Setup(provider => provider.GetUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + urlHelper.Setup(provider => provider.GetUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(UrlInfo.Url("/hello/world/1234")); var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), AppCaches.Disabled, Mock.Of(), new MockShortStringHelper(), Mock.Of()); diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs index 7230d1101e..70c3707b04 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs @@ -109,7 +109,7 @@ namespace Umbraco.Tests.TestHelpers /// /// An Umbraco context. /// This should be the minimum Umbraco context. - public UmbracoContext GetUmbracoContextMock(IUmbracoContextAccessor accessor = null) + public IUmbracoContext GetUmbracoContextMock(IUmbracoContextAccessor accessor = null) { var httpContext = Mock.Of(); diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index 86442d89c0..faeb5b10ec 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -357,7 +357,7 @@ namespace Umbraco.Tests.TestHelpers } } - protected UmbracoContext GetUmbracoContext(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable urlProviders = null, IEnumerable mediaUrlProviders = null, IGlobalSettings globalSettings = null, IPublishedSnapshotService snapshotService = null) + protected IUmbracoContext GetUmbracoContext(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable urlProviders = null, IEnumerable mediaUrlProviders = null, IGlobalSettings globalSettings = null, IPublishedSnapshotService snapshotService = null) { // ensure we have a PublishedCachesService var service = snapshotService ?? PublishedSnapshotService as XmlPublishedSnapshotService; diff --git a/src/Umbraco.Tests/Testing/Objects/Accessors/TestUmbracoContextAccessor.cs b/src/Umbraco.Tests/Testing/Objects/Accessors/TestUmbracoContextAccessor.cs index 4f3b801af9..f9862701ea 100644 --- a/src/Umbraco.Tests/Testing/Objects/Accessors/TestUmbracoContextAccessor.cs +++ b/src/Umbraco.Tests/Testing/Objects/Accessors/TestUmbracoContextAccessor.cs @@ -4,13 +4,13 @@ namespace Umbraco.Tests.Testing.Objects.Accessors { public class TestUmbracoContextAccessor : IUmbracoContextAccessor { - public UmbracoContext UmbracoContext { get; set; } + public IUmbracoContext UmbracoContext { get; set; } public TestUmbracoContextAccessor() { } - public TestUmbracoContextAccessor(UmbracoContext umbracoContext) + public TestUmbracoContextAccessor(IUmbracoContext umbracoContext) { UmbracoContext = umbracoContext; } diff --git a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs index 6f807f62c5..724eb29266 100644 --- a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs +++ b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs @@ -81,7 +81,7 @@ namespace Umbraco.Tests.Testing.TestingTests var umbracoContext = TestObjects.GetUmbracoContextMock(); var urlProviderMock = new Mock(); - urlProviderMock.Setup(provider => provider.GetUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + urlProviderMock.Setup(provider => provider.GetUrl(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns(UrlInfo.Url("/hello/world/1234")); var urlProvider = urlProviderMock.Object; diff --git a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs index adc0cbe770..c99d2cd943 100644 --- a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs @@ -404,7 +404,7 @@ namespace Umbraco.Tests.Web.Mvc return context; } - protected UmbracoContext GetUmbracoContext(ILogger logger, IUmbracoSettingsSection umbracoSettings, string url, int templateId, RouteData routeData = null, bool setSingleton = false) + protected IUmbracoContext GetUmbracoContext(ILogger logger, IUmbracoSettingsSection umbracoSettings, string url, int templateId, RouteData routeData = null, bool setSingleton = false) { var svcCtx = GetServiceContext(); diff --git a/src/Umbraco.Web/Composing/Current.cs b/src/Umbraco.Web/Composing/Current.cs index bd2326b35a..f9b0edb49a 100644 --- a/src/Umbraco.Web/Composing/Current.cs +++ b/src/Umbraco.Web/Composing/Current.cs @@ -108,7 +108,7 @@ namespace Umbraco.Web.Composing #region Web Getters - public static UmbracoContext UmbracoContext + public static IUmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext; public static UmbracoHelper UmbracoHelper diff --git a/src/Umbraco.Web/Editors/EditorModelEventArgs.cs b/src/Umbraco.Web/Editors/EditorModelEventArgs.cs index daf262fce5..24ee1a3d85 100644 --- a/src/Umbraco.Web/Editors/EditorModelEventArgs.cs +++ b/src/Umbraco.Web/Editors/EditorModelEventArgs.cs @@ -14,7 +14,7 @@ namespace Umbraco.Web.Editors Model = (T)baseArgs.Model; } - public EditorModelEventArgs(T model, UmbracoContext umbracoContext) + public EditorModelEventArgs(T model, IUmbracoContext umbracoContext) : base(model, umbracoContext) { Model = model; @@ -34,13 +34,13 @@ namespace Umbraco.Web.Editors public class EditorModelEventArgs : EventArgs { - public EditorModelEventArgs(object model, UmbracoContext umbracoContext) + public EditorModelEventArgs(object model, IUmbracoContext umbracoContext) { Model = model; UmbracoContext = umbracoContext; } public object Model { get; set; } - public UmbracoContext UmbracoContext { get; } + public IUmbracoContext UmbracoContext { get; } } } diff --git a/src/Umbraco.Web/Editors/Filters/UserGroupAuthorizationAttribute.cs b/src/Umbraco.Web/Editors/Filters/UserGroupAuthorizationAttribute.cs index 454d81666a..daa3ae3491 100644 --- a/src/Umbraco.Web/Editors/Filters/UserGroupAuthorizationAttribute.cs +++ b/src/Umbraco.Web/Editors/Filters/UserGroupAuthorizationAttribute.cs @@ -33,7 +33,7 @@ namespace Umbraco.Web.Editors.Filters _paramName = paramName; } - private UmbracoContext GetUmbracoContext() + private IUmbracoContext GetUmbracoContext() { return _umbracoContextAccessor?.UmbracoContext ?? Composing.Current.UmbracoContext; } diff --git a/src/Umbraco.Web/HttpContextUmbracoContextAccessor.cs b/src/Umbraco.Web/HttpContextUmbracoContextAccessor.cs index 5a05ee85ff..a6f89ec154 100644 --- a/src/Umbraco.Web/HttpContextUmbracoContextAccessor.cs +++ b/src/Umbraco.Web/HttpContextUmbracoContextAccessor.cs @@ -12,13 +12,13 @@ namespace Umbraco.Web _httpContextAccessor = httpContextAccessor; } - public UmbracoContext UmbracoContext + public IUmbracoContext UmbracoContext { get { var httpContext = _httpContextAccessor.HttpContext; if (httpContext == null) throw new Exception("oops:httpContext"); - return (UmbracoContext) httpContext.Items[HttpContextItemKey]; + return (IUmbracoContext) httpContext.Items[HttpContextItemKey]; } set diff --git a/src/Umbraco.Web/HybridUmbracoContextAccessor.cs b/src/Umbraco.Web/HybridUmbracoContextAccessor.cs index d5d03d58bb..3c22826f30 100644 --- a/src/Umbraco.Web/HybridUmbracoContextAccessor.cs +++ b/src/Umbraco.Web/HybridUmbracoContextAccessor.cs @@ -3,7 +3,7 @@ /// /// Implements a hybrid . /// - internal class HybridUmbracoContextAccessor : HybridAccessorBase, IUmbracoContextAccessor + internal class HybridUmbracoContextAccessor : HybridAccessorBase, IUmbracoContextAccessor { /// /// Initializes a new instance of the class. @@ -18,7 +18,7 @@ /// /// Gets or sets the object. /// - public UmbracoContext UmbracoContext + public IUmbracoContext UmbracoContext { get => Value; set => Value = value; diff --git a/src/Umbraco.Web/IUmbracoContext.cs b/src/Umbraco.Web/IUmbracoContext.cs new file mode 100644 index 0000000000..8a624a8132 --- /dev/null +++ b/src/Umbraco.Web/IUmbracoContext.cs @@ -0,0 +1,135 @@ +using System; +using System.Web; +using Umbraco.Core.Models.PublishedContent; +using Umbraco.Web.PublishedCache; +using Umbraco.Web.Routing; +using Umbraco.Web.Security; + +namespace Umbraco.Web +{ + public interface IUmbracoContext + { + /// + /// 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. + /// We can then determine complete rendering time from that. + /// + DateTime ObjectCreated { get; } + + /// + /// This is used internally for debugging and also used to define anything required to distinguish this request from another. + /// + Guid UmbracoRequestId { get; } + + /// + /// Gets the WebSecurity class + /// + WebSecurity Security { get; } + + /// + /// Gets the uri that is handled by ASP.NET after server-side rewriting took place. + /// + Uri OriginalRequestUrl { get; } + + /// + /// Gets the cleaned up url that is handled by Umbraco. + /// + /// That is, lowercase, no trailing slash after path, no .aspx... + Uri CleanedUmbracoUrl { get; } + + /// + /// Gets the published snapshot. + /// + IPublishedSnapshot PublishedSnapshot { get; } + + /// + /// Gets the published content cache. + /// + IPublishedContentCache Content { get; } + + /// + /// Gets the published media cache. + /// + IPublishedMediaCache Media { get; } + + /// + /// Gets the domains cache. + /// + IDomainCache Domains { get; } + + /// + /// Boolean value indicating whether the current request is a front-end umbraco request + /// + bool IsFrontEndUmbracoRequest { get; } + + /// + /// Gets the url provider. + /// + UrlProvider UrlProvider { get; } + + /// + /// Gets/sets the PublishedRequest object + /// + PublishedRequest PublishedRequest { get; set; } + + /// + /// Exposes the HttpContext for the current request + /// + HttpContextBase HttpContext { get; } + + /// + /// Gets the variation context accessor. + /// + IVariationContextAccessor VariationContextAccessor { get; } + + /// + /// Gets a value indicating whether the request has debugging enabled + /// + /// true if this instance is debug; otherwise, false. + bool IsDebug { get; } + + /// + /// Determines whether the current user is in a preview mode and browsing the site (ie. not in the admin UI) + /// + bool InPreviewMode { get; } + + string PreviewToken { get; } + + /// + /// Gets the url of a content identified by its identifier. + /// + /// The content identifier. + /// + /// The url for the content. + string Url(int contentId, string culture = null); + + /// + /// Gets the url of a content identified by its identifier. + /// + /// The content identifier. + /// + /// The url for the content. + string Url(Guid contentId, string culture = null); + + /// + /// Gets the url of a content identified by its identifier, in a specified mode. + /// + /// The content identifier. + /// The mode. + /// + /// The url for the content. + string Url(int contentId, UrlMode mode, string culture = null); + + /// + /// Gets the url of a content identified by its identifier, in a specified mode. + /// + /// The content identifier. + /// The mode. + /// + /// The url for the content. + string Url(Guid contentId, UrlMode mode, string culture = null); + + IDisposable ForcedPreview(bool preview); + void Dispose(); + } +} diff --git a/src/Umbraco.Web/IUmbracoContextAccessor.cs b/src/Umbraco.Web/IUmbracoContextAccessor.cs index 74df940865..5c7549bff6 100644 --- a/src/Umbraco.Web/IUmbracoContextAccessor.cs +++ b/src/Umbraco.Web/IUmbracoContextAccessor.cs @@ -5,6 +5,6 @@ /// public interface IUmbracoContextAccessor { - UmbracoContext UmbracoContext { get; set; } + IUmbracoContext UmbracoContext { get; set; } } } diff --git a/src/Umbraco.Web/IUmbracoContextFactory.cs b/src/Umbraco.Web/IUmbracoContextFactory.cs index 6d89578da7..37e7fa0880 100644 --- a/src/Umbraco.Web/IUmbracoContextFactory.cs +++ b/src/Umbraco.Web/IUmbracoContextFactory.cs @@ -3,15 +3,15 @@ namespace Umbraco.Web { /// - /// Creates and manages instances. + /// Creates and manages instances. /// public interface IUmbracoContextFactory { /// - /// Ensures that a current exists. + /// Ensures that a current exists. /// /// - /// If an is already registered in the + /// If an is already registered in the /// , returns a non-root reference to it. /// Otherwise, create a new instance, registers it, and return a root reference /// to it. diff --git a/src/Umbraco.Web/Install/HttpInstallAuthorizeAttribute.cs b/src/Umbraco.Web/Install/HttpInstallAuthorizeAttribute.cs index 4cf844669f..ad02f1248d 100644 --- a/src/Umbraco.Web/Install/HttpInstallAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Install/HttpInstallAuthorizeAttribute.cs @@ -27,7 +27,7 @@ namespace Umbraco.Web.Install private IRuntimeState RuntimeState => _runtimeState ?? Current.RuntimeState; - private UmbracoContext UmbracoContext => _umbracoContextAccessor?.UmbracoContext ?? Current.UmbracoContext; + private IUmbracoContext UmbracoContext => _umbracoContextAccessor?.UmbracoContext ?? Current.UmbracoContext; /// /// THIS SHOULD BE ONLY USED FOR UNIT TESTS diff --git a/src/Umbraco.Web/Install/InstallAuthorizeAttribute.cs b/src/Umbraco.Web/Install/InstallAuthorizeAttribute.cs index da2f2bab57..df6802bd51 100644 --- a/src/Umbraco.Web/Install/InstallAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Install/InstallAuthorizeAttribute.cs @@ -19,7 +19,7 @@ namespace Umbraco.Web.Install private IRuntimeState RuntimeState => _runtimeState ?? Current.RuntimeState; - private UmbracoContext UmbracoContext => _umbracoContextAccessor?.UmbracoContext ?? Current.UmbracoContext; + private IUmbracoContext UmbracoContext => _umbracoContextAccessor?.UmbracoContext ?? Current.UmbracoContext; /// /// THIS SHOULD BE ONLY USED FOR UNIT TESTS diff --git a/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs b/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs index 44ee77507b..ecfda80399 100644 --- a/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs +++ b/src/Umbraco.Web/Macros/PartialViewMacroEngine.cs @@ -16,7 +16,7 @@ namespace Umbraco.Web.Macros public class PartialViewMacroEngine { private readonly Func _getHttpContext; - private readonly Func _getUmbracoContext; + private readonly Func _getUmbracoContext; public PartialViewMacroEngine() { @@ -40,7 +40,7 @@ namespace Umbraco.Web.Macros /// /// /// - internal PartialViewMacroEngine(HttpContextBase httpContext, UmbracoContext umbracoContext) + internal PartialViewMacroEngine(HttpContextBase httpContext, IUmbracoContext umbracoContext) { _getHttpContext = () => httpContext; _getUmbracoContext = () => umbracoContext; diff --git a/src/Umbraco.Web/Models/Mapping/RedirectUrlMapDefinition.cs b/src/Umbraco.Web/Models/Mapping/RedirectUrlMapDefinition.cs index e773fcfee5..c7d65ed56d 100644 --- a/src/Umbraco.Web/Models/Mapping/RedirectUrlMapDefinition.cs +++ b/src/Umbraco.Web/Models/Mapping/RedirectUrlMapDefinition.cs @@ -13,7 +13,7 @@ namespace Umbraco.Web.Models.Mapping _umbracoContextAccessor = umbracoContextAccessor; } - private UmbracoContext UmbracoContext => _umbracoContextAccessor.UmbracoContext; + private IUmbracoContext UmbracoContext => _umbracoContextAccessor.UmbracoContext; public void DefineMaps(UmbracoMapper mapper) { diff --git a/src/Umbraco.Web/Mvc/ControllerContextExtensions.cs b/src/Umbraco.Web/Mvc/ControllerContextExtensions.cs index 393b6882c9..4baaaac4fc 100644 --- a/src/Umbraco.Web/Mvc/ControllerContextExtensions.cs +++ b/src/Umbraco.Web/Mvc/ControllerContextExtensions.cs @@ -10,10 +10,10 @@ namespace Umbraco.Web.Mvc /// /// The controller context. /// The Umbraco context. - public static UmbracoContext GetUmbracoContext(this ControllerContext controllerContext) + public static IUmbracoContext GetUmbracoContext(this ControllerContext controllerContext) { var o = controllerContext.GetDataTokenInViewContextHierarchy(Core.Constants.Web.UmbracoContextDataToken); - return o != null ? o as UmbracoContext : Current.UmbracoContext; + return o != null ? o as IUmbracoContext : Current.UmbracoContext; } /// diff --git a/src/Umbraco.Web/Mvc/EnsurePublishedContentRequestAttribute.cs b/src/Umbraco.Web/Mvc/EnsurePublishedContentRequestAttribute.cs index 187c64d93a..31a3d6a9ea 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 => _umbracoContextAccessor?.UmbracoContext ?? Current.UmbracoContext; + protected IUmbracoContext UmbracoContext => _umbracoContextAccessor?.UmbracoContext ?? Current.UmbracoContext; // TODO: try lazy property injection? private IPublishedRouter PublishedRouter => Current.Factory.GetInstance(); diff --git a/src/Umbraco.Web/Mvc/PluginController.cs b/src/Umbraco.Web/Mvc/PluginController.cs index 9e080ee042..a87f495c9b 100644 --- a/src/Umbraco.Web/Mvc/PluginController.cs +++ b/src/Umbraco.Web/Mvc/PluginController.cs @@ -27,7 +27,7 @@ namespace Umbraco.Web.Mvc /// /// Gets the Umbraco context. /// - public virtual UmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext; + public virtual IUmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext; /// /// Gets the database context accessor. diff --git a/src/Umbraco.Web/Mvc/RedirectToUmbracoUrlResult.cs b/src/Umbraco.Web/Mvc/RedirectToUmbracoUrlResult.cs index ddc989eb57..3690e98790 100644 --- a/src/Umbraco.Web/Mvc/RedirectToUmbracoUrlResult.cs +++ b/src/Umbraco.Web/Mvc/RedirectToUmbracoUrlResult.cs @@ -13,13 +13,13 @@ namespace Umbraco.Web.Mvc /// public class RedirectToUmbracoUrlResult : ActionResult { - private readonly UmbracoContext _umbracoContext; + private readonly IUmbracoContext _umbracoContext; /// /// Creates a new RedirectToUmbracoResult /// /// - public RedirectToUmbracoUrlResult(UmbracoContext umbracoContext) + public RedirectToUmbracoUrlResult(IUmbracoContext umbracoContext) { _umbracoContext = umbracoContext; } diff --git a/src/Umbraco.Web/Mvc/RenderMvcController.cs b/src/Umbraco.Web/Mvc/RenderMvcController.cs index 64c9ad52c4..4d191d8f30 100644 --- a/src/Umbraco.Web/Mvc/RenderMvcController.cs +++ b/src/Umbraco.Web/Mvc/RenderMvcController.cs @@ -34,7 +34,7 @@ namespace Umbraco.Web.Mvc /// /// Gets the Umbraco context. /// - public override UmbracoContext UmbracoContext => PublishedRequest.UmbracoContext; //TODO: Why? + public override IUmbracoContext UmbracoContext => PublishedRequest.UmbracoContext; //TODO: Why? /// /// Gets the current content item. diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index fdf38e78b3..186c9f212a 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -29,7 +29,7 @@ namespace Umbraco.Web.Mvc private readonly IControllerFactory _controllerFactory; private readonly IShortStringHelper _shortStringHelper; private readonly IUmbracoContextAccessor _umbracoContextAccessor; - private readonly UmbracoContext _umbracoContext; + private readonly IUmbracoContext _umbracoContext; public RenderRouteHandler(IUmbracoContextAccessor umbracoContextAccessor, IControllerFactory controllerFactory, IShortStringHelper shortStringHelper) { @@ -38,14 +38,14 @@ namespace Umbraco.Web.Mvc _shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper)); } - public RenderRouteHandler(UmbracoContext umbracoContext, IControllerFactory controllerFactory, IShortStringHelper shortStringHelper) + public RenderRouteHandler(IUmbracoContext umbracoContext, IControllerFactory controllerFactory, IShortStringHelper shortStringHelper) { _umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext)); _controllerFactory = controllerFactory ?? throw new ArgumentNullException(nameof(controllerFactory)); _shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper)); } - private UmbracoContext UmbracoContext => _umbracoContext ?? _umbracoContextAccessor.UmbracoContext; + private IUmbracoContext UmbracoContext => _umbracoContext ?? _umbracoContextAccessor.UmbracoContext; private UmbracoFeatures Features => Current.Factory.GetInstance(); // TODO: inject diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs index fa0b1c5458..0c6898553c 100644 --- a/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs +++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizeAttribute.cs @@ -13,20 +13,20 @@ namespace Umbraco.Web.Mvc public sealed class UmbracoAuthorizeAttribute : AuthorizeAttribute { // see note in HttpInstallAuthorizeAttribute - private readonly UmbracoContext _umbracoContext; + private readonly IUmbracoContext _umbracoContext; private readonly IRuntimeState _runtimeState; private readonly string _redirectUrl; private IRuntimeState RuntimeState => _runtimeState ?? Current.RuntimeState; - private UmbracoContext UmbracoContext => _umbracoContext ?? Current.UmbracoContext; + private IUmbracoContext UmbracoContext => _umbracoContext ?? Current.UmbracoContext; /// /// THIS SHOULD BE ONLY USED FOR UNIT TESTS /// /// /// - public UmbracoAuthorizeAttribute(UmbracoContext umbracoContext, IRuntimeState runtimeState) + public UmbracoAuthorizeAttribute(IUmbracoContext umbracoContext, IRuntimeState runtimeState) { if (umbracoContext == null) throw new ArgumentNullException(nameof(umbracoContext)); if (runtimeState == null) throw new ArgumentNullException(nameof(runtimeState)); diff --git a/src/Umbraco.Web/Mvc/UmbracoController.cs b/src/Umbraco.Web/Mvc/UmbracoController.cs index 6841bf5875..3056a9837a 100644 --- a/src/Umbraco.Web/Mvc/UmbracoController.cs +++ b/src/Umbraco.Web/Mvc/UmbracoController.cs @@ -28,7 +28,7 @@ namespace Umbraco.Web.Mvc /// /// Gets the Umbraco context. /// - public virtual UmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext; + public virtual IUmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext; /// /// Gets or sets the Umbraco context accessor. diff --git a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs index 97a8eaf294..6e01f76abe 100644 --- a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs +++ b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs @@ -25,7 +25,7 @@ namespace Umbraco.Web.Mvc private readonly IGlobalSettings _globalSettings; private readonly IUmbracoSettingsSection _umbracoSettingsSection; - private UmbracoContext _umbracoContext; + private IUmbracoContext _umbracoContext; private UmbracoHelper _helper; /// @@ -50,7 +50,7 @@ namespace Umbraco.Web.Mvc /// /// Gets the Umbraco context. /// - public UmbracoContext UmbracoContext => _umbracoContext + public IUmbracoContext UmbracoContext => _umbracoContext ?? (_umbracoContext = ViewContext.GetUmbracoContext() ?? Current.UmbracoContext); /// diff --git a/src/Umbraco.Web/Mvc/UmbracoVirtualNodeByIdRouteHandler.cs b/src/Umbraco.Web/Mvc/UmbracoVirtualNodeByIdRouteHandler.cs index 0ada310b12..ae38bb945d 100644 --- a/src/Umbraco.Web/Mvc/UmbracoVirtualNodeByIdRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/UmbracoVirtualNodeByIdRouteHandler.cs @@ -12,13 +12,13 @@ namespace Umbraco.Web.Mvc _realNodeId = realNodeId; } - protected sealed override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext) + protected sealed override IPublishedContent FindContent(RequestContext requestContext, IUmbracoContext umbracoContext) { var byId = umbracoContext.Content.GetById(_realNodeId); return byId == null ? null : FindContent(requestContext, umbracoContext, byId); } - protected virtual IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext, IPublishedContent baseContent) + protected virtual IPublishedContent FindContent(RequestContext requestContext, IUmbracoContext umbracoContext, IPublishedContent baseContent) { return baseContent; } diff --git a/src/Umbraco.Web/Mvc/UmbracoVirtualNodeByUdiRouteHandler.cs b/src/Umbraco.Web/Mvc/UmbracoVirtualNodeByUdiRouteHandler.cs index a1ee6c732a..7aee823b9a 100644 --- a/src/Umbraco.Web/Mvc/UmbracoVirtualNodeByUdiRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/UmbracoVirtualNodeByUdiRouteHandler.cs @@ -13,13 +13,13 @@ namespace Umbraco.Web.Mvc _realNodeUdi = realNodeUdi; } - protected sealed override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext) + protected sealed override IPublishedContent FindContent(RequestContext requestContext, IUmbracoContext umbracoContext) { var byId = umbracoContext.Content.GetById(_realNodeUdi); return byId == null ? null : FindContent(requestContext, umbracoContext, byId); } - protected virtual IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext, IPublishedContent baseContent) + protected virtual IPublishedContent FindContent(RequestContext requestContext, IUmbracoContext umbracoContext, IPublishedContent baseContent) { return baseContent; } diff --git a/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs b/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs index 8fc8b255a8..9d6b336265 100644 --- a/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/UmbracoVirtualNodeRouteHandler.cs @@ -38,7 +38,7 @@ namespace Umbraco.Web.Mvc /// ]]> /// /// - protected virtual UmbracoContext GetUmbracoContext(RequestContext requestContext) + protected virtual IUmbracoContext GetUmbracoContext(RequestContext requestContext) { return Composing.Current.UmbracoContext; } @@ -88,7 +88,7 @@ namespace Umbraco.Web.Mvc return new MvcHandler(requestContext); } - protected abstract IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext); + protected abstract IPublishedContent FindContent(RequestContext requestContext, IUmbracoContext umbracoContext); protected virtual void PreparePublishedContentRequest(PublishedRequest request) { diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index 11e8bd9f64..e4d2524c80 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -25,7 +25,7 @@ namespace Umbraco.Web // private static IPublishedValueFallback PublishedValueFallback => Current.PublishedValueFallback; private static IPublishedSnapshot PublishedSnapshot => Current.PublishedSnapshot; - private static UmbracoContext UmbracoContext => Current.UmbracoContext; + private static IUmbracoContext UmbracoContext => Current.UmbracoContext; private static ISiteDomainHelper SiteDomainHelper => Current.Factory.GetInstance(); private static IVariationContextAccessor VariationContextAccessor => Current.VariationContextAccessor; private static IExamineManager ExamineManager => Current.Factory.GetInstance(); diff --git a/src/Umbraco.Web/Routing/AliasUrlProvider.cs b/src/Umbraco.Web/Routing/AliasUrlProvider.cs index f84ac608d2..849a85dd2c 100644 --- a/src/Umbraco.Web/Routing/AliasUrlProvider.cs +++ b/src/Umbraco.Web/Routing/AliasUrlProvider.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.Routing #region GetUrl /// - public UrlInfo GetUrl(UmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current) + public UrlInfo GetUrl(IUmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current) { return null; // we have nothing to say } @@ -51,7 +51,7 @@ namespace Umbraco.Web.Routing /// Other urls are those that GetUrl would not return in the current context, but would be valid /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...). /// - public IEnumerable GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current) + public IEnumerable GetOtherUrls(IUmbracoContext umbracoContext, int id, Uri current) { var node = umbracoContext.Content.GetById(id); if (node == null) diff --git a/src/Umbraco.Web/Routing/DefaultMediaUrlProvider.cs b/src/Umbraco.Web/Routing/DefaultMediaUrlProvider.cs index beaf5f5864..c7c987e0e5 100644 --- a/src/Umbraco.Web/Routing/DefaultMediaUrlProvider.cs +++ b/src/Umbraco.Web/Routing/DefaultMediaUrlProvider.cs @@ -18,7 +18,7 @@ namespace Umbraco.Web.Routing } /// - public virtual UrlInfo GetMediaUrl(UmbracoContext umbracoContext, IPublishedContent content, + public virtual UrlInfo GetMediaUrl(IUmbracoContext umbracoContext, IPublishedContent content, string propertyAlias, UrlMode mode, string culture, Uri current) { var prop = content.GetProperty(propertyAlias); diff --git a/src/Umbraco.Web/Routing/DefaultUrlProvider.cs b/src/Umbraco.Web/Routing/DefaultUrlProvider.cs index 4092538481..43d4d5dd90 100644 --- a/src/Umbraco.Web/Routing/DefaultUrlProvider.cs +++ b/src/Umbraco.Web/Routing/DefaultUrlProvider.cs @@ -29,7 +29,7 @@ namespace Umbraco.Web.Routing #region GetUrl /// - public virtual UrlInfo GetUrl(UmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current) + public virtual UrlInfo GetUrl(IUmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current) { if (!current.IsAbsoluteUri) throw new ArgumentException("Current url must be absolute.", nameof(current)); @@ -39,7 +39,7 @@ namespace Umbraco.Web.Routing return GetUrlFromRoute(route, umbracoContext, content.Id, current, mode, culture); } - internal UrlInfo GetUrlFromRoute(string route, UmbracoContext umbracoContext, int id, Uri current, UrlMode mode, string culture) + internal UrlInfo GetUrlFromRoute(string route, IUmbracoContext umbracoContext, int id, Uri current, UrlMode mode, string culture) { if (string.IsNullOrWhiteSpace(route)) { @@ -76,7 +76,7 @@ namespace Umbraco.Web.Routing /// Other urls are those that GetUrl would not return in the current context, but would be valid /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...). /// - public virtual IEnumerable GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current) + public virtual IEnumerable GetOtherUrls(IUmbracoContext umbracoContext, int id, Uri current) { var node = umbracoContext.Content.GetById(id); if (node == null) diff --git a/src/Umbraco.Web/Routing/DomainUtilities.cs b/src/Umbraco.Web/Routing/DomainUtilities.cs index fb0c56b28d..9255ee46ef 100644 --- a/src/Umbraco.Web/Routing/DomainUtilities.cs +++ b/src/Umbraco.Web/Routing/DomainUtilities.cs @@ -27,7 +27,7 @@ namespace Umbraco.Web.Routing /// one document per culture), and domains, withing the context of a current Uri, assign /// a culture to that document. /// - internal static string GetCultureFromDomains(int contentId, string contentPath, Uri current, UmbracoContext umbracoContext, ISiteDomainHelper siteDomainHelper) + internal static string GetCultureFromDomains(int contentId, string contentPath, Uri current, IUmbracoContext umbracoContext, ISiteDomainHelper siteDomainHelper) { if (umbracoContext == null) throw new InvalidOperationException("A current UmbracoContext is required."); diff --git a/src/Umbraco.Web/Routing/IMediaUrlProvider.cs b/src/Umbraco.Web/Routing/IMediaUrlProvider.cs index 8a81b27415..0c128057f1 100644 --- a/src/Umbraco.Web/Routing/IMediaUrlProvider.cs +++ b/src/Umbraco.Web/Routing/IMediaUrlProvider.cs @@ -26,6 +26,6 @@ namespace Umbraco.Web.Routing /// e.g. a cdn url provider will most likely always return an absolute url. /// If the provider is unable to provide a url, it returns null. /// - UrlInfo GetMediaUrl(UmbracoContext umbracoContext, IPublishedContent content, string propertyAlias, UrlMode mode, string culture, Uri current); + UrlInfo GetMediaUrl(IUmbracoContext umbracoContext, IPublishedContent content, string propertyAlias, UrlMode mode, string culture, Uri current); } } diff --git a/src/Umbraco.Web/Routing/IPublishedRouter.cs b/src/Umbraco.Web/Routing/IPublishedRouter.cs index df06e42e55..77502612c3 100644 --- a/src/Umbraco.Web/Routing/IPublishedRouter.cs +++ b/src/Umbraco.Web/Routing/IPublishedRouter.cs @@ -17,7 +17,7 @@ namespace Umbraco.Web.Routing /// The current Umbraco context. /// The (optional) request Uri. /// A published request. - PublishedRequest CreateRequest(UmbracoContext umbracoContext, Uri uri = null); + PublishedRequest CreateRequest(IUmbracoContext umbracoContext, Uri uri = null); /// /// Prepares a request for rendering. diff --git a/src/Umbraco.Web/Routing/IUrlProvider.cs b/src/Umbraco.Web/Routing/IUrlProvider.cs index c0ce1fef39..16c1a1c91c 100644 --- a/src/Umbraco.Web/Routing/IUrlProvider.cs +++ b/src/Umbraco.Web/Routing/IUrlProvider.cs @@ -24,7 +24,7 @@ namespace Umbraco.Web.Routing /// when no culture is specified, the current culture. /// If the provider is unable to provide a url, it should return null. /// - UrlInfo GetUrl(UmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current); + UrlInfo GetUrl(IUmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current); /// /// Gets the other urls of a published content. @@ -37,6 +37,6 @@ namespace Umbraco.Web.Routing /// Other urls are those that GetUrl would not return in the current context, but would be valid /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...). /// - IEnumerable GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current); + IEnumerable GetOtherUrls(IUmbracoContext umbracoContext, int id, Uri current); } } diff --git a/src/Umbraco.Web/Routing/PublishedRequest.cs b/src/Umbraco.Web/Routing/PublishedRequest.cs index 37a58ad375..becdbc8d27 100644 --- a/src/Umbraco.Web/Routing/PublishedRequest.cs +++ b/src/Umbraco.Web/Routing/PublishedRequest.cs @@ -37,7 +37,7 @@ namespace Umbraco.Web.Routing /// The published router. /// The Umbraco context. /// The request Uri. - internal PublishedRequest(IPublishedRouter publishedRouter, UmbracoContext umbracoContext, IUmbracoSettingsSection umbracoSettingsSection, Uri uri = null) + internal PublishedRequest(IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, IUmbracoSettingsSection umbracoSettingsSection, Uri uri = null) { UmbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext)); _publishedRouter = publishedRouter ?? throw new ArgumentNullException(nameof(publishedRouter)); @@ -48,7 +48,7 @@ namespace Umbraco.Web.Routing /// /// Gets the UmbracoContext. /// - public UmbracoContext UmbracoContext { get; } + public IUmbracoContext UmbracoContext { get; } /// /// Gets or sets the cleaned up Uri used for routing. diff --git a/src/Umbraco.Web/Routing/PublishedRouter.cs b/src/Umbraco.Web/Routing/PublishedRouter.cs index 9148ce2e31..82041f04fa 100644 --- a/src/Umbraco.Web/Routing/PublishedRouter.cs +++ b/src/Umbraco.Web/Routing/PublishedRouter.cs @@ -55,7 +55,7 @@ namespace Umbraco.Web.Routing } /// - public PublishedRequest CreateRequest(UmbracoContext umbracoContext, Uri uri = null) + public PublishedRequest CreateRequest(IUmbracoContext umbracoContext, Uri uri = null) { return new PublishedRequest(this, umbracoContext, _umbracoSettingsSection, uri ?? umbracoContext.CleanedUmbracoUrl); } diff --git a/src/Umbraco.Web/Routing/RoutableAttemptEventArgs.cs b/src/Umbraco.Web/Routing/RoutableAttemptEventArgs.cs index 96b377b103..eea33f95fe 100644 --- a/src/Umbraco.Web/Routing/RoutableAttemptEventArgs.cs +++ b/src/Umbraco.Web/Routing/RoutableAttemptEventArgs.cs @@ -9,7 +9,7 @@ namespace Umbraco.Web.Routing { public EnsureRoutableOutcome Outcome { get; private set; } - public RoutableAttemptEventArgs(EnsureRoutableOutcome reason, UmbracoContext umbracoContext, HttpContextBase httpContext) + public RoutableAttemptEventArgs(EnsureRoutableOutcome reason, IUmbracoContext umbracoContext, HttpContextBase httpContext) : base(umbracoContext, httpContext) { Outcome = reason; diff --git a/src/Umbraco.Web/Routing/UmbracoRequestEventArgs.cs b/src/Umbraco.Web/Routing/UmbracoRequestEventArgs.cs index 5b2be178fd..56c9c9f07d 100644 --- a/src/Umbraco.Web/Routing/UmbracoRequestEventArgs.cs +++ b/src/Umbraco.Web/Routing/UmbracoRequestEventArgs.cs @@ -8,10 +8,10 @@ namespace Umbraco.Web.Routing /// public class UmbracoRequestEventArgs : EventArgs { - public UmbracoContext UmbracoContext { get; private set; } + public IUmbracoContext UmbracoContext { get; private set; } public HttpContextBase HttpContext { get; private set; } - public UmbracoRequestEventArgs(UmbracoContext umbracoContext, HttpContextBase httpContext) + public UmbracoRequestEventArgs(IUmbracoContext umbracoContext, HttpContextBase httpContext) { UmbracoContext = umbracoContext; HttpContext = httpContext; diff --git a/src/Umbraco.Web/Routing/UrlProvider.cs b/src/Umbraco.Web/Routing/UrlProvider.cs index d42639b781..8720d4c52a 100644 --- a/src/Umbraco.Web/Routing/UrlProvider.cs +++ b/src/Umbraco.Web/Routing/UrlProvider.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.Routing /// The list of url providers. /// The list of media url providers. /// The current variation accessor. - public UrlProvider(UmbracoContext umbracoContext, IWebRoutingSection routingSettings, IEnumerable urlProviders, IEnumerable mediaUrlProviders, IVariationContextAccessor variationContextAccessor) + public UrlProvider(IUmbracoContext umbracoContext, IWebRoutingSection routingSettings, IEnumerable urlProviders, IEnumerable mediaUrlProviders, IVariationContextAccessor variationContextAccessor) { if (routingSettings == null) throw new ArgumentNullException(nameof(routingSettings)); @@ -48,7 +48,7 @@ namespace Umbraco.Web.Routing /// The list of media url providers /// The current variation accessor. /// An optional provider mode. - public UrlProvider(UmbracoContext umbracoContext, IEnumerable urlProviders, IEnumerable mediaUrlProviders, IVariationContextAccessor variationContextAccessor, UrlMode mode = UrlMode.Auto) + public UrlProvider(IUmbracoContext umbracoContext, IEnumerable urlProviders, IEnumerable mediaUrlProviders, IVariationContextAccessor variationContextAccessor, UrlMode mode = UrlMode.Auto) { _umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext)); _urlProviders = urlProviders; @@ -58,7 +58,7 @@ namespace Umbraco.Web.Routing Mode = mode; } - private readonly UmbracoContext _umbracoContext; + private readonly IUmbracoContext _umbracoContext; private readonly IEnumerable _urlProviders; private readonly IEnumerable _mediaUrlProviders; private readonly IVariationContextAccessor _variationContextAccessor; diff --git a/src/Umbraco.Web/Routing/UrlProviderExtensions.cs b/src/Umbraco.Web/Routing/UrlProviderExtensions.cs index 9a0579daa1..e4359ad03e 100644 --- a/src/Umbraco.Web/Routing/UrlProviderExtensions.cs +++ b/src/Umbraco.Web/Routing/UrlProviderExtensions.cs @@ -20,7 +20,7 @@ namespace Umbraco.Web.Routing /// public static IEnumerable GetContentUrls(this IContent content, IPublishedRouter publishedRouter, - UmbracoContext umbracoContext, + IUmbracoContext umbracoContext, ILocalizationService localizationService, ILocalizedTextService textService, IContentService contentService, @@ -96,7 +96,7 @@ namespace Umbraco.Web.Routing private static IEnumerable GetContentUrlsByCulture(IContent content, IEnumerable cultures, IPublishedRouter publishedRouter, - UmbracoContext umbracoContext, + IUmbracoContext umbracoContext, IContentService contentService, ILocalizedTextService textService, IVariationContextAccessor variationContextAccessor, @@ -165,7 +165,7 @@ namespace Umbraco.Web.Routing return UrlInfo.Message(textService.Localize("content/parentCultureNotPublished", new[] {parent.Name}), culture); } - private static bool DetectCollision(IContent content, string url, string culture, UmbracoContext umbracoContext, IPublishedRouter publishedRouter, ILocalizedTextService textService, IVariationContextAccessor variationContextAccessor, out UrlInfo urlInfo) + private static bool DetectCollision(IContent content, string url, string culture, IUmbracoContext umbracoContext, IPublishedRouter publishedRouter, ILocalizedTextService textService, IVariationContextAccessor variationContextAccessor, out UrlInfo urlInfo) { // test for collisions on the 'main' url var uri = new Uri(url.TrimEnd('/'), UriKind.RelativeOrAbsolute); diff --git a/src/Umbraco.Web/Runtime/WebInitialComposer.cs b/src/Umbraco.Web/Runtime/WebInitialComposer.cs index be551181c4..c06d8e3777 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComposer.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComposer.cs @@ -81,7 +81,7 @@ namespace Umbraco.Web.Runtime composition.Register(factory => MembershipProviderExtensions.GetMembersMembershipProvider()); composition.Register(factory => Roles.Enabled ? Roles.Provider : new MembersRoleProvider(factory.GetInstance())); composition.Register(Lifetime.Request); - composition.Register(factory => factory.GetInstance().PublishedSnapshot.Members); + composition.Register(factory => factory.GetInstance().PublishedSnapshot.Members); // register accessors for cultures composition.RegisterUnique(); @@ -131,7 +131,7 @@ namespace Umbraco.Web.Runtime if (composition.RuntimeState.Level == RuntimeLevel.Run) composition.Register(factory => { - var umbCtx = factory.GetInstance(); + var umbCtx = factory.GetInstance(); return new UmbracoHelper(umbCtx.IsFrontEndUmbracoRequest ? umbCtx.PublishedRequest?.PublishedContent : null, factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs index 0f52384409..a905320cc5 100644 --- a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs +++ b/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs @@ -20,7 +20,7 @@ namespace Umbraco.Web.Search /// public class UmbracoTreeSearcher { - private readonly UmbracoContext _umbracoContext; + private readonly IUmbracoContext _umbracoContext; private readonly ILocalizationService _languageService; private readonly IEntityService _entityService; private readonly UmbracoMapper _mapper; @@ -28,7 +28,7 @@ namespace Umbraco.Web.Search private readonly IBackOfficeExamineSearcher _backOfficeExamineSearcher; - public UmbracoTreeSearcher(UmbracoContext umbracoContext, + public UmbracoTreeSearcher(IUmbracoContext umbracoContext, ILocalizationService languageService, IEntityService entityService, UmbracoMapper mapper, diff --git a/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs b/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs index 56773293da..283f6b6b99 100644 --- a/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs +++ b/src/Umbraco.Web/Security/ExternalSignInAutoLinkOptions.cs @@ -48,7 +48,7 @@ namespace Umbraco.Web.Security /// /// /// - public string[] GetDefaultUserGroups(UmbracoContext umbracoContext, ExternalLoginInfo loginInfo) + public string[] GetDefaultUserGroups(IUmbracoContext umbracoContext, ExternalLoginInfo loginInfo) { return _defaultUserGroups; } @@ -61,7 +61,7 @@ namespace Umbraco.Web.Security /// /// For public auth providers this should always be false!!! /// - public bool ShouldAutoLinkExternalAccount(UmbracoContext umbracoContext, ExternalLoginInfo loginInfo) + public bool ShouldAutoLinkExternalAccount(IUmbracoContext umbracoContext, ExternalLoginInfo loginInfo) { return _autoLinkExternalAccount; } @@ -71,7 +71,7 @@ namespace Umbraco.Web.Security /// /// The default Culture to use for auto-linking users /// - public string GetDefaultCulture(UmbracoContext umbracoContext, ExternalLoginInfo loginInfo) + public string GetDefaultCulture(IUmbracoContext umbracoContext, ExternalLoginInfo loginInfo) { return _defaultCulture; } diff --git a/src/Umbraco.Web/Security/IUmbracoBackOfficeTwoFactorOptions.cs b/src/Umbraco.Web/Security/IUmbracoBackOfficeTwoFactorOptions.cs index acd49ec5e0..0b43342594 100644 --- a/src/Umbraco.Web/Security/IUmbracoBackOfficeTwoFactorOptions.cs +++ b/src/Umbraco.Web/Security/IUmbracoBackOfficeTwoFactorOptions.cs @@ -7,6 +7,6 @@ namespace Umbraco.Web.Security /// public interface IUmbracoBackOfficeTwoFactorOptions { - string GetTwoFactorView(IOwinContext owinContext, UmbracoContext umbracoContext, string username); + string GetTwoFactorView(IOwinContext owinContext, IUmbracoContext umbracoContext, string username); } } diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 3ce6c64342..6cbb4afa9a 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -246,6 +246,7 @@ + @@ -715,7 +716,7 @@ Code - + diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 3b00c67b42..374b78c333 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -1,27 +1,22 @@ using System; using System.Collections.Generic; -using System.IO; using System.Web; -using System.Web.Routing; using Umbraco.Core; -using Umbraco.Web.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; -using Umbraco.Web; +using Umbraco.Web.Composing; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; namespace Umbraco.Web { - /// /// Class that encapsulates Umbraco information of a specific HTTP request /// - public class UmbracoContext : DisposableObjectSlim, IDisposeOnRequestEnd + public class UmbracoContext : DisposableObjectSlim, IDisposeOnRequestEnd, IUmbracoContext { private readonly IGlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; @@ -88,12 +83,12 @@ namespace Umbraco.Web /// object is instantiated which in the web site is created during the BeginRequest phase. /// We can then determine complete rendering time from that. /// - internal DateTime ObjectCreated { get; } + public DateTime ObjectCreated { get; } /// /// This is used internally for debugging and also used to define anything required to distinguish this request from another. /// - internal Guid UmbracoRequestId { get; } + public Guid UmbracoRequestId { get; } /// /// Gets the WebSecurity class @@ -103,13 +98,13 @@ namespace Umbraco.Web /// /// Gets the uri that is handled by ASP.NET after server-side rewriting took place. /// - internal Uri OriginalRequestUrl { get; } + public Uri OriginalRequestUrl { get; } /// /// Gets the cleaned up url that is handled by Umbraco. /// /// That is, lowercase, no trailing slash after path, no .aspx... - internal Uri CleanedUmbracoUrl { get; } + public Uri CleanedUmbracoUrl { get; } /// /// Gets the published snapshot. @@ -167,10 +162,10 @@ namespace Umbraco.Web var request = GetRequestFromContext(); //NOTE: the request can be null during app startup! return Current.RuntimeState.Debug - && request != null - && (string.IsNullOrEmpty(request["umbdebugshowtrace"]) == false - || string.IsNullOrEmpty(request["umbdebug"]) == false - || string.IsNullOrEmpty(request.Cookies["UMB-DEBUG"]?.Value) == false); + && request != null + && (string.IsNullOrEmpty(request["umbdebugshowtrace"]) == false + || string.IsNullOrEmpty(request["umbdebug"]) == false + || string.IsNullOrEmpty(request.Cookies["UMB-DEBUG"]?.Value) == false); } } @@ -237,7 +232,7 @@ namespace Umbraco.Web #endregion - private string PreviewToken + public string PreviewToken { get { @@ -263,7 +258,7 @@ namespace Umbraco.Web // say we render a macro or RTE in a give 'preview' mode that might not be the 'current' one, // then due to the way it all works at the moment, the 'current' published snapshot need to be in the proper // default 'preview' mode - somehow we have to force it. and that could be recursive. - internal IDisposable ForcedPreview(bool preview) + public IDisposable ForcedPreview(bool preview) { InPreviewMode = preview; return PublishedSnapshot.ForcedPreview(preview, orig => InPreviewMode = orig); diff --git a/src/Umbraco.Web/UmbracoContextFactory.cs b/src/Umbraco.Web/UmbracoContextFactory.cs index cc618bfc82..bb6d307250 100644 --- a/src/Umbraco.Web/UmbracoContextFactory.cs +++ b/src/Umbraco.Web/UmbracoContextFactory.cs @@ -16,7 +16,7 @@ using Umbraco.Web.Security; namespace Umbraco.Web { /// - /// Creates and manages instances. + /// Creates and manages instances. /// public class UmbracoContextFactory : IUmbracoContextFactory { @@ -52,7 +52,7 @@ namespace Umbraco.Web _ioHelper = ioHelper; } - private UmbracoContext CreateUmbracoContext(HttpContextBase httpContext) + private IUmbracoContext CreateUmbracoContext(HttpContextBase httpContext) { // make sure we have a variation context if (_variationContextAccessor.VariationContext == null) diff --git a/src/Umbraco.Web/UmbracoContextReference.cs b/src/Umbraco.Web/UmbracoContextReference.cs index 6c4ac7e54a..740f972bbf 100644 --- a/src/Umbraco.Web/UmbracoContextReference.cs +++ b/src/Umbraco.Web/UmbracoContextReference.cs @@ -20,7 +20,7 @@ namespace Umbraco.Web /// /// Initializes a new instance of the class. /// - internal UmbracoContextReference(UmbracoContext umbracoContext, bool isRoot, IUmbracoContextAccessor umbracoContextAccessor) + internal UmbracoContextReference(IUmbracoContext umbracoContext, bool isRoot, IUmbracoContextAccessor umbracoContextAccessor) { UmbracoContext = umbracoContext; IsRoot = isRoot; @@ -31,7 +31,7 @@ namespace Umbraco.Web /// /// Gets the . /// - public UmbracoContext UmbracoContext { get; } + public IUmbracoContext UmbracoContext { get; } /// /// Gets a value indicating whether the reference is a root reference. diff --git a/src/Umbraco.Web/UmbracoInjectedModule.cs b/src/Umbraco.Web/UmbracoInjectedModule.cs index f8725632ae..8b840461d5 100644 --- a/src/Umbraco.Web/UmbracoInjectedModule.cs +++ b/src/Umbraco.Web/UmbracoInjectedModule.cs @@ -155,7 +155,7 @@ namespace Umbraco.Web /// /// /// - internal Attempt EnsureUmbracoRoutablePage(UmbracoContext context, HttpContextBase httpContext) + internal Attempt EnsureUmbracoRoutablePage(IUmbracoContext context, HttpContextBase httpContext) { var uri = context.OriginalRequestUrl; @@ -230,7 +230,7 @@ namespace Umbraco.Web // ensures Umbraco has at least one published node // if not, rewrites to splash and return false // if yes, return true - private bool EnsureHasContent(UmbracoContext context, HttpContextBase httpContext) + private bool EnsureHasContent(IUmbracoContext context, HttpContextBase httpContext) { if (context.Content.HasContent()) return true; diff --git a/src/Umbraco.Web/UmbracoWebService.cs b/src/Umbraco.Web/UmbracoWebService.cs index bccdb5771d..ed78314560 100644 --- a/src/Umbraco.Web/UmbracoWebService.cs +++ b/src/Umbraco.Web/UmbracoWebService.cs @@ -49,7 +49,7 @@ namespace Umbraco.Web /// /// Gets the Umbraco context. /// - public UmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext; + public IUmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext; /// /// Gets the Umbraco context accessor. diff --git a/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs b/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs index f019ffe2df..9b35416def 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiControllerBase.cs @@ -75,7 +75,7 @@ namespace Umbraco.Web.WebApi /// /// Gets the Umbraco context. /// - public virtual UmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext; + public virtual IUmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext; /// /// Gets the Umbraco context accessor. diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizeAttribute.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizeAttribute.cs index 49cb75fffb..7566a4d78f 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizeAttribute.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizeAttribute.cs @@ -20,19 +20,19 @@ namespace Umbraco.Web.WebApi internal static bool Enable = true; // TODO: inject! - private readonly UmbracoContext _umbracoContext; + private readonly IUmbracoContext _umbracoContext; private readonly IRuntimeState _runtimeState; private IRuntimeState RuntimeState => _runtimeState ?? Current.RuntimeState; - private UmbracoContext UmbracoContext => _umbracoContext ?? Current.UmbracoContext; + private IUmbracoContext UmbracoContext => _umbracoContext ?? Current.UmbracoContext; /// /// THIS SHOULD BE ONLY USED FOR UNIT TESTS /// /// /// - public UmbracoAuthorizeAttribute(UmbracoContext umbracoContext, IRuntimeState runtimeState) + public UmbracoAuthorizeAttribute(IUmbracoContext umbracoContext, IRuntimeState runtimeState) { if (umbracoContext == null) throw new ArgumentNullException(nameof(umbracoContext)); if (runtimeState == null) throw new ArgumentNullException(nameof(runtimeState));