Introduced interface on UmbracoContext
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Umbraco.Tests.Composing
|
||||
var typesFound = typeFinder.FindClassesWithAttribute<TreeAttribute>(_assemblies);
|
||||
Assert.AreEqual(0, typesFound.Count()); // 0 classes in _assemblies are marked with [Tree]
|
||||
|
||||
typesFound = typeFinder.FindClassesWithAttribute<TreeAttribute>(new[] { typeof (UmbracoContext).Assembly });
|
||||
typesFound = typeFinder.FindClassesWithAttribute<TreeAttribute>(new[] { typeof (IUmbracoContext).Assembly });
|
||||
Assert.AreEqual(22, typesFound.Count()); // + classes in Umbraco.Web are marked with [Tree]
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
|
||||
{
|
||||
static class UmbracoContextCache
|
||||
{
|
||||
static readonly ConditionalWeakTable<UmbracoContext, ConcurrentDictionary<string, object>> Caches
|
||||
= new ConditionalWeakTable<UmbracoContext, ConcurrentDictionary<string, object>>();
|
||||
static readonly ConditionalWeakTable<IUmbracoContext, ConcurrentDictionary<string, object>> Caches
|
||||
= new ConditionalWeakTable<IUmbracoContext, ConcurrentDictionary<string, object>>();
|
||||
|
||||
public static ConcurrentDictionary<string, object> Current
|
||||
{
|
||||
|
||||
@@ -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<string, PublishedContentType> _contentTypes;
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
.ToList());
|
||||
}
|
||||
|
||||
private UmbracoContext GetUmbracoContext()
|
||||
private IUmbracoContext GetUmbracoContext()
|
||||
{
|
||||
RouteData routeData = null;
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
/// <param name="id"></param>
|
||||
/// <param name="umbracoContext"></param>
|
||||
/// <returns></returns>
|
||||
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,
|
||||
|
||||
@@ -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<IUrlProvider> urlProviders = null)
|
||||
protected IUmbracoContext GetUmbracoContextNu(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable<IUrlProvider> urlProviders = null)
|
||||
{
|
||||
// ensure we have a PublishedSnapshotService
|
||||
var service = PublishedSnapshotService as PublishedSnapshotService;
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Umbraco.Tests.Templates
|
||||
var media = new Mock<IPublishedContent>();
|
||||
media.Setup(x => x.ContentType).Returns(mediaType);
|
||||
var mediaUrlProvider = new Mock<IMediaUrlProvider>();
|
||||
mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny<UmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<string>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny<IUmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<string>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/media/1001/my-image.jpg"));
|
||||
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Umbraco.Tests.Templates
|
||||
//setup a mock url provider which we'll use for testing
|
||||
var contentUrlProvider = new Mock<IUrlProvider>();
|
||||
contentUrlProvider
|
||||
.Setup(x => x.GetUrl(It.IsAny<UmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Setup(x => x.GetUrl(It.IsAny<IUmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/my-test-url"));
|
||||
var contentType = new PublishedContentType(666, "alias", PublishedItemType.Content, Enumerable.Empty<string>(), Enumerable.Empty<PublishedPropertyType>(), ContentVariation.Nothing);
|
||||
var publishedContent = new Mock<IPublishedContent>();
|
||||
@@ -63,7 +63,7 @@ namespace Umbraco.Tests.Templates
|
||||
var media = new Mock<IPublishedContent>();
|
||||
media.Setup(x => x.ContentType).Returns(mediaType);
|
||||
var mediaUrlProvider = new Mock<IMediaUrlProvider>();
|
||||
mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny<UmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<string>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny<IUmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<string>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/media/1001/my-image.jpg"));
|
||||
|
||||
var umbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
umbracoContextAccessor.UmbracoContext = umbCtx;
|
||||
|
||||
var urlHelper = new Mock<IUrlProvider>();
|
||||
urlHelper.Setup(provider => provider.GetUrl(It.IsAny<UmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
urlHelper.Setup(provider => provider.GetUrl(It.IsAny<IUmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/hello/world/1234"));
|
||||
|
||||
var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), new MockShortStringHelper(), Mock.Of<IEntityService>());
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
/// </summary>
|
||||
/// <returns>An Umbraco context.</returns>
|
||||
/// <remarks>This should be the minimum Umbraco context.</remarks>
|
||||
public UmbracoContext GetUmbracoContextMock(IUmbracoContextAccessor accessor = null)
|
||||
public IUmbracoContext GetUmbracoContextMock(IUmbracoContextAccessor accessor = null)
|
||||
{
|
||||
var httpContext = Mock.Of<HttpContextBase>();
|
||||
|
||||
|
||||
@@ -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<IUrlProvider> urlProviders = null, IEnumerable<IMediaUrlProvider> 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<IUrlProvider> urlProviders = null, IEnumerable<IMediaUrlProvider> mediaUrlProviders = null, IGlobalSettings globalSettings = null, IPublishedSnapshotService snapshotService = null)
|
||||
{
|
||||
// ensure we have a PublishedCachesService
|
||||
var service = snapshotService ?? PublishedSnapshotService as XmlPublishedSnapshotService;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Umbraco.Tests.Testing.TestingTests
|
||||
var umbracoContext = TestObjects.GetUmbracoContextMock();
|
||||
|
||||
var urlProviderMock = new Mock<IUrlProvider>();
|
||||
urlProviderMock.Setup(provider => provider.GetUrl(It.IsAny<UmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
urlProviderMock.Setup(provider => provider.GetUrl(It.IsAny<IUmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns(UrlInfo.Url("/hello/world/1234"));
|
||||
var urlProvider = urlProviderMock.Object;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Umbraco.Web.Editors.Filters
|
||||
_paramName = paramName;
|
||||
}
|
||||
|
||||
private UmbracoContext GetUmbracoContext()
|
||||
private IUmbracoContext GetUmbracoContext()
|
||||
{
|
||||
return _umbracoContextAccessor?.UmbracoContext ?? Composing.Current.UmbracoContext;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Implements a hybrid <see cref="IUmbracoContextAccessor"/>.
|
||||
/// </summary>
|
||||
internal class HybridUmbracoContextAccessor : HybridAccessorBase<UmbracoContext>, IUmbracoContextAccessor
|
||||
internal class HybridUmbracoContextAccessor : HybridAccessorBase<IUmbracoContext>, IUmbracoContextAccessor
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HybridUmbracoContextAccessor"/> class.
|
||||
@@ -18,7 +18,7 @@
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="UmbracoContext"/> object.
|
||||
/// </summary>
|
||||
public UmbracoContext UmbracoContext
|
||||
public IUmbracoContext UmbracoContext
|
||||
{
|
||||
get => Value;
|
||||
set => Value = value;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
DateTime ObjectCreated { get; }
|
||||
|
||||
/// <summary>
|
||||
/// This is used internally for debugging and also used to define anything required to distinguish this request from another.
|
||||
/// </summary>
|
||||
Guid UmbracoRequestId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WebSecurity class
|
||||
/// </summary>
|
||||
WebSecurity Security { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the uri that is handled by ASP.NET after server-side rewriting took place.
|
||||
/// </summary>
|
||||
Uri OriginalRequestUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cleaned up url that is handled by Umbraco.
|
||||
/// </summary>
|
||||
/// <remarks>That is, lowercase, no trailing slash after path, no .aspx...</remarks>
|
||||
Uri CleanedUmbracoUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the published snapshot.
|
||||
/// </summary>
|
||||
IPublishedSnapshot PublishedSnapshot { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the published content cache.
|
||||
/// </summary>
|
||||
IPublishedContentCache Content { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the published media cache.
|
||||
/// </summary>
|
||||
IPublishedMediaCache Media { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the domains cache.
|
||||
/// </summary>
|
||||
IDomainCache Domains { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Boolean value indicating whether the current request is a front-end umbraco request
|
||||
/// </summary>
|
||||
bool IsFrontEndUmbracoRequest { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url provider.
|
||||
/// </summary>
|
||||
UrlProvider UrlProvider { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the PublishedRequest object
|
||||
/// </summary>
|
||||
PublishedRequest PublishedRequest { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Exposes the HttpContext for the current request
|
||||
/// </summary>
|
||||
HttpContextBase HttpContext { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the variation context accessor.
|
||||
/// </summary>
|
||||
IVariationContextAccessor VariationContextAccessor { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the request has debugging enabled
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if this instance is debug; otherwise, <c>false</c>.</value>
|
||||
bool IsDebug { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the current user is in a preview mode and browsing the site (ie. not in the admin UI)
|
||||
/// </summary>
|
||||
bool InPreviewMode { get; }
|
||||
|
||||
string PreviewToken { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of a content identified by its identifier.
|
||||
/// </summary>
|
||||
/// <param name="contentId">The content identifier.</param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns>The url for the content.</returns>
|
||||
string Url(int contentId, string culture = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of a content identified by its identifier.
|
||||
/// </summary>
|
||||
/// <param name="contentId">The content identifier.</param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns>The url for the content.</returns>
|
||||
string Url(Guid contentId, string culture = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of a content identified by its identifier, in a specified mode.
|
||||
/// </summary>
|
||||
/// <param name="contentId">The content identifier.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns>The url for the content.</returns>
|
||||
string Url(int contentId, UrlMode mode, string culture = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url of a content identified by its identifier, in a specified mode.
|
||||
/// </summary>
|
||||
/// <param name="contentId">The content identifier.</param>
|
||||
/// <param name="mode">The mode.</param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns>The url for the content.</returns>
|
||||
string Url(Guid contentId, UrlMode mode, string culture = null);
|
||||
|
||||
IDisposable ForcedPreview(bool preview);
|
||||
void Dispose();
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,6 @@
|
||||
/// </summary>
|
||||
public interface IUmbracoContextAccessor
|
||||
{
|
||||
UmbracoContext UmbracoContext { get; set; }
|
||||
IUmbracoContext UmbracoContext { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates and manages <see cref="UmbracoContext"/> instances.
|
||||
/// Creates and manages <see cref="IUmbracoContext"/> instances.
|
||||
/// </summary>
|
||||
public interface IUmbracoContextFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Ensures that a current <see cref="UmbracoContext"/> exists.
|
||||
/// Ensures that a current <see cref="IUmbracoContext"/> exists.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>If an <see cref="UmbracoContext"/> is already registered in the
|
||||
/// <para>If an <see cref="IUmbracoContext"/> is already registered in the
|
||||
/// <see cref="IUmbracoContextAccessor"/>, returns a non-root reference to it.
|
||||
/// Otherwise, create a new instance, registers it, and return a root reference
|
||||
/// to it.</para>
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// THIS SHOULD BE ONLY USED FOR UNIT TESTS
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// THIS SHOULD BE ONLY USED FOR UNIT TESTS
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Umbraco.Web.Macros
|
||||
public class PartialViewMacroEngine
|
||||
{
|
||||
private readonly Func<HttpContextBase> _getHttpContext;
|
||||
private readonly Func<UmbracoContext> _getUmbracoContext;
|
||||
private readonly Func<IUmbracoContext> _getUmbracoContext;
|
||||
|
||||
public PartialViewMacroEngine()
|
||||
{
|
||||
@@ -40,7 +40,7 @@ namespace Umbraco.Web.Macros
|
||||
/// </summary>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <param name="umbracoContext"> </param>
|
||||
internal PartialViewMacroEngine(HttpContextBase httpContext, UmbracoContext umbracoContext)
|
||||
internal PartialViewMacroEngine(HttpContextBase httpContext, IUmbracoContext umbracoContext)
|
||||
{
|
||||
_getHttpContext = () => httpContext;
|
||||
_getUmbracoContext = () => umbracoContext;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -10,10 +10,10 @@ namespace Umbraco.Web.Mvc
|
||||
/// </summary>
|
||||
/// <param name="controllerContext">The controller context.</param>
|
||||
/// <returns>The Umbraco context.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// <summary>
|
||||
/// Exposes the UmbracoContext
|
||||
/// </summary>
|
||||
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<IPublishedRouter>();
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// <summary>
|
||||
/// Gets the Umbraco context.
|
||||
/// </summary>
|
||||
public virtual UmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext;
|
||||
public virtual IUmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the database context accessor.
|
||||
|
||||
@@ -13,13 +13,13 @@ namespace Umbraco.Web.Mvc
|
||||
/// </remarks>
|
||||
public class RedirectToUmbracoUrlResult : ActionResult
|
||||
{
|
||||
private readonly UmbracoContext _umbracoContext;
|
||||
private readonly IUmbracoContext _umbracoContext;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new RedirectToUmbracoResult
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext"></param>
|
||||
public RedirectToUmbracoUrlResult(UmbracoContext umbracoContext)
|
||||
public RedirectToUmbracoUrlResult(IUmbracoContext umbracoContext)
|
||||
{
|
||||
_umbracoContext = umbracoContext;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// <summary>
|
||||
/// Gets the Umbraco context.
|
||||
/// </summary>
|
||||
public override UmbracoContext UmbracoContext => PublishedRequest.UmbracoContext; //TODO: Why?
|
||||
public override IUmbracoContext UmbracoContext => PublishedRequest.UmbracoContext; //TODO: Why?
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current content item.
|
||||
|
||||
@@ -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<UmbracoFeatures>(); // TODO: inject
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// THIS SHOULD BE ONLY USED FOR UNIT TESTS
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext"></param>
|
||||
/// <param name="runtimeState"></param>
|
||||
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));
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// <summary>
|
||||
/// Gets the Umbraco context.
|
||||
/// </summary>
|
||||
public virtual UmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext;
|
||||
public virtual IUmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Umbraco context accessor.
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
@@ -50,7 +50,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// <summary>
|
||||
/// Gets the Umbraco context.
|
||||
/// </summary>
|
||||
public UmbracoContext UmbracoContext => _umbracoContext
|
||||
public IUmbracoContext UmbracoContext => _umbracoContext
|
||||
?? (_umbracoContext = ViewContext.GetUmbracoContext() ?? Current.UmbracoContext);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace Umbraco.Web.Mvc
|
||||
/// ]]>
|
||||
/// </example>
|
||||
/// </remarks>
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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<ISiteDomainHelper>();
|
||||
private static IVariationContextAccessor VariationContextAccessor => Current.VariationContextAccessor;
|
||||
private static IExamineManager ExamineManager => Current.Factory.GetInstance<IExamineManager>();
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Umbraco.Web.Routing
|
||||
#region GetUrl
|
||||
|
||||
/// <inheritdoc />
|
||||
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
|
||||
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
|
||||
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
|
||||
/// </remarks>
|
||||
public IEnumerable<UrlInfo> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
|
||||
public IEnumerable<UrlInfo> GetOtherUrls(IUmbracoContext umbracoContext, int id, Uri current)
|
||||
{
|
||||
var node = umbracoContext.Content.GetById(id);
|
||||
if (node == null)
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Umbraco.Web.Routing
|
||||
#region GetUrl
|
||||
|
||||
/// <inheritdoc />
|
||||
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
|
||||
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
|
||||
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
|
||||
/// </remarks>
|
||||
public virtual IEnumerable<UrlInfo> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
|
||||
public virtual IEnumerable<UrlInfo> GetOtherUrls(IUmbracoContext umbracoContext, int id, Uri current)
|
||||
{
|
||||
var node = umbracoContext.Content.GetById(id);
|
||||
if (node == null)
|
||||
|
||||
@@ -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.</para>
|
||||
/// </remarks>
|
||||
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.");
|
||||
|
||||
@@ -26,6 +26,6 @@ namespace Umbraco.Web.Routing
|
||||
/// e.g. a cdn url provider will most likely always return an absolute url.</para>
|
||||
/// <para>If the provider is unable to provide a url, it returns <c>null</c>.</para>
|
||||
/// </remarks>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <param name="umbracoContext">The current Umbraco context.</param>
|
||||
/// <param name="uri">The (optional) request Uri.</param>
|
||||
/// <returns>A published request.</returns>
|
||||
PublishedRequest CreateRequest(UmbracoContext umbracoContext, Uri uri = null);
|
||||
PublishedRequest CreateRequest(IUmbracoContext umbracoContext, Uri uri = null);
|
||||
|
||||
/// <summary>
|
||||
/// Prepares a request for rendering.
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Umbraco.Web.Routing
|
||||
/// when no culture is specified, the current culture.</para>
|
||||
/// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para>
|
||||
/// </remarks>
|
||||
UrlInfo GetUrl(UmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current);
|
||||
UrlInfo GetUrl(IUmbracoContext umbracoContext, IPublishedContent content, UrlMode mode, string culture, Uri current);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the other urls of a published content.
|
||||
@@ -37,6 +37,6 @@ namespace Umbraco.Web.Routing
|
||||
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
|
||||
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
|
||||
/// </remarks>
|
||||
IEnumerable<UrlInfo> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current);
|
||||
IEnumerable<UrlInfo> GetOtherUrls(IUmbracoContext umbracoContext, int id, Uri current);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <param name="publishedRouter">The published router.</param>
|
||||
/// <param name="umbracoContext">The Umbraco context.</param>
|
||||
/// <param name="uri">The request <c>Uri</c>.</param>
|
||||
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
|
||||
/// <summary>
|
||||
/// Gets the UmbracoContext.
|
||||
/// </summary>
|
||||
public UmbracoContext UmbracoContext { get; }
|
||||
public IUmbracoContext UmbracoContext { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the cleaned up Uri used for routing.
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -8,10 +8,10 @@ namespace Umbraco.Web.Routing
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <param name="urlProviders">The list of url providers.</param>
|
||||
/// <param name="mediaUrlProviders">The list of media url providers.</param>
|
||||
/// <param name="variationContextAccessor">The current variation accessor.</param>
|
||||
public UrlProvider(UmbracoContext umbracoContext, IWebRoutingSection routingSettings, IEnumerable<IUrlProvider> urlProviders, IEnumerable<IMediaUrlProvider> mediaUrlProviders, IVariationContextAccessor variationContextAccessor)
|
||||
public UrlProvider(IUmbracoContext umbracoContext, IWebRoutingSection routingSettings, IEnumerable<IUrlProvider> urlProviders, IEnumerable<IMediaUrlProvider> mediaUrlProviders, IVariationContextAccessor variationContextAccessor)
|
||||
{
|
||||
if (routingSettings == null) throw new ArgumentNullException(nameof(routingSettings));
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <param name="mediaUrlProviders">The list of media url providers</param>
|
||||
/// <param name="variationContextAccessor">The current variation accessor.</param>
|
||||
/// <param name="mode">An optional provider mode.</param>
|
||||
public UrlProvider(UmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders, IEnumerable<IMediaUrlProvider> mediaUrlProviders, IVariationContextAccessor variationContextAccessor, UrlMode mode = UrlMode.Auto)
|
||||
public UrlProvider(IUmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders, IEnumerable<IMediaUrlProvider> 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<IUrlProvider> _urlProviders;
|
||||
private readonly IEnumerable<IMediaUrlProvider> _mediaUrlProviders;
|
||||
private readonly IVariationContextAccessor _variationContextAccessor;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Umbraco.Web.Routing
|
||||
/// </remarks>
|
||||
public static IEnumerable<UrlInfo> 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<UrlInfo> GetContentUrlsByCulture(IContent content,
|
||||
IEnumerable<string> 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);
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Umbraco.Web.Runtime
|
||||
composition.Register(factory => MembershipProviderExtensions.GetMembersMembershipProvider());
|
||||
composition.Register(factory => Roles.Enabled ? Roles.Provider : new MembersRoleProvider(factory.GetInstance<IMemberService>()));
|
||||
composition.Register<MembershipHelper>(Lifetime.Request);
|
||||
composition.Register<IPublishedMemberCache>(factory => factory.GetInstance<UmbracoContext>().PublishedSnapshot.Members);
|
||||
composition.Register<IPublishedMemberCache>(factory => factory.GetInstance<IUmbracoContext>().PublishedSnapshot.Members);
|
||||
|
||||
// register accessors for cultures
|
||||
composition.RegisterUnique<IDefaultCultureAccessor, DefaultCultureAccessor>();
|
||||
@@ -131,7 +131,7 @@ namespace Umbraco.Web.Runtime
|
||||
if (composition.RuntimeState.Level == RuntimeLevel.Run)
|
||||
composition.Register<UmbracoHelper>(factory =>
|
||||
{
|
||||
var umbCtx = factory.GetInstance<UmbracoContext>();
|
||||
var umbCtx = factory.GetInstance<IUmbracoContext>();
|
||||
return new UmbracoHelper(umbCtx.IsFrontEndUmbracoRequest ? umbCtx.PublishedRequest?.PublishedContent : null,
|
||||
factory.GetInstance<ITagQuery>(), factory.GetInstance<ICultureDictionaryFactory>(),
|
||||
factory.GetInstance<IUmbracoComponentRenderer>(), factory.GetInstance<IPublishedContentQuery>(),
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Umbraco.Web.Search
|
||||
/// </summary>
|
||||
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,
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Umbraco.Web.Security
|
||||
/// <param name="umbracoContext"></param>
|
||||
/// <param name="loginInfo"></param>
|
||||
/// <returns></returns>
|
||||
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!!!
|
||||
/// </summary>
|
||||
public bool ShouldAutoLinkExternalAccount(UmbracoContext umbracoContext, ExternalLoginInfo loginInfo)
|
||||
public bool ShouldAutoLinkExternalAccount(IUmbracoContext umbracoContext, ExternalLoginInfo loginInfo)
|
||||
{
|
||||
return _autoLinkExternalAccount;
|
||||
}
|
||||
@@ -71,7 +71,7 @@ namespace Umbraco.Web.Security
|
||||
/// <summary>
|
||||
/// The default Culture to use for auto-linking users
|
||||
/// </summary>
|
||||
public string GetDefaultCulture(UmbracoContext umbracoContext, ExternalLoginInfo loginInfo)
|
||||
public string GetDefaultCulture(IUmbracoContext umbracoContext, ExternalLoginInfo loginInfo)
|
||||
{
|
||||
return _defaultCulture;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ namespace Umbraco.Web.Security
|
||||
/// </summary>
|
||||
public interface IUmbracoBackOfficeTwoFactorOptions
|
||||
{
|
||||
string GetTwoFactorView(IOwinContext owinContext, UmbracoContext umbracoContext, string username);
|
||||
string GetTwoFactorView(IOwinContext owinContext, IUmbracoContext umbracoContext, string username);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,6 +246,7 @@
|
||||
<Compile Include="Templates\HtmlUrlParser.cs" />
|
||||
<Compile Include="Trees\TreeCollectionBuilder.cs" />
|
||||
<Compile Include="Trees\TreeNode.cs" />
|
||||
<Compile Include="UmbracoContext.cs" />
|
||||
<Compile Include="UmbracoContextFactory.cs" />
|
||||
<Compile Include="UmbracoContextReference.cs" />
|
||||
<Compile Include="Mvc\UmbracoVirtualNodeByUdiRouteHandler.cs" />
|
||||
@@ -715,7 +716,7 @@
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="UmbracoApplication.cs" />
|
||||
<Compile Include="UmbracoContext.cs" />
|
||||
<Compile Include="IUmbracoContext.cs" />
|
||||
<Compile Include="UmbracoInjectedModule.cs" />
|
||||
<Compile Include="UriUtility.cs" />
|
||||
<Compile Include="Web References\org.umbraco.update\Reference.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
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Class that encapsulates Umbraco information of a specific HTTP request
|
||||
/// </summary>
|
||||
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.
|
||||
/// </summary>
|
||||
internal DateTime ObjectCreated { get; }
|
||||
public DateTime ObjectCreated { get; }
|
||||
|
||||
/// <summary>
|
||||
/// This is used internally for debugging and also used to define anything required to distinguish this request from another.
|
||||
/// </summary>
|
||||
internal Guid UmbracoRequestId { get; }
|
||||
public Guid UmbracoRequestId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WebSecurity class
|
||||
@@ -103,13 +98,13 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Gets the uri that is handled by ASP.NET after server-side rewriting took place.
|
||||
/// </summary>
|
||||
internal Uri OriginalRequestUrl { get; }
|
||||
public Uri OriginalRequestUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cleaned up url that is handled by Umbraco.
|
||||
/// </summary>
|
||||
/// <remarks>That is, lowercase, no trailing slash after path, no .aspx...</remarks>
|
||||
internal Uri CleanedUmbracoUrl { get; }
|
||||
public Uri CleanedUmbracoUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
|
||||
@@ -16,7 +16,7 @@ using Umbraco.Web.Security;
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates and manages <see cref="UmbracoContext"/> instances.
|
||||
/// Creates and manages <see cref="IUmbracoContext"/> instances.
|
||||
/// </summary>
|
||||
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)
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UmbracoContextReference"/> class.
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
/// Gets the <see cref="UmbracoContext"/>.
|
||||
/// </summary>
|
||||
public UmbracoContext UmbracoContext { get; }
|
||||
public IUmbracoContext UmbracoContext { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the reference is a root reference.
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace Umbraco.Web
|
||||
/// <param name="context"></param>
|
||||
/// <param name="httpContext"></param>
|
||||
/// <returns></returns>
|
||||
internal Attempt<EnsureRoutableOutcome> EnsureUmbracoRoutablePage(UmbracoContext context, HttpContextBase httpContext)
|
||||
internal Attempt<EnsureRoutableOutcome> 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;
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Gets the Umbraco context.
|
||||
/// </summary>
|
||||
public UmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext;
|
||||
public IUmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Umbraco context accessor.
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Umbraco.Web.WebApi
|
||||
/// <summary>
|
||||
/// Gets the Umbraco context.
|
||||
/// </summary>
|
||||
public virtual UmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext;
|
||||
public virtual IUmbracoContext UmbracoContext => UmbracoContextAccessor.UmbracoContext;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Umbraco context accessor.
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// THIS SHOULD BE ONLY USED FOR UNIT TESTS
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext"></param>
|
||||
/// <param name="runtimeState"></param>
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user