diff --git a/src/Umbraco.Tests/PublishedContent/DynamicXmlTests.cs b/src/Umbraco.Tests/PublishedContent/DynamicXmlTests.cs index a566ce5cee..53d8efd1ad 100644 --- a/src/Umbraco.Tests/PublishedContent/DynamicXmlTests.cs +++ b/src/Umbraco.Tests/PublishedContent/DynamicXmlTests.cs @@ -16,7 +16,7 @@ namespace Umbraco.Tests.PublishedContent /// http://issues.umbraco.org/issue/U4-1636 /// [Test] - public void Deals_With_Hyphenated_values() + public void Deals_With_Hyphenated_Values() { var xml = @" diff --git a/src/Umbraco.Web/UI/Controls/UmbracoControl.cs b/src/Umbraco.Web/UI/Controls/UmbracoControl.cs index 0bb461a1ad..66f896312e 100644 --- a/src/Umbraco.Web/UI/Controls/UmbracoControl.cs +++ b/src/Umbraco.Web/UI/Controls/UmbracoControl.cs @@ -1,4 +1,8 @@ -using System.Web.UI; +using System; +using System.Web; +using System.Web.Mvc; +using System.Web.Routing; +using System.Web.UI; using Umbraco.Core; using Umbraco.Core.Services; using umbraco.BusinessLogic; @@ -6,26 +10,37 @@ using umbraco.DataLayer; namespace Umbraco.Web.UI.Controls { - /// + /// /// A control that exposes the helpful Umbraco context objects /// - internal class UmbracoControl : Control + public abstract class UmbracoControl : Control { - public UmbracoControl(UmbracoContext umbracoContext) - { - _umbracoContext = umbracoContext; - } + /// + /// Default constructor + /// + /// + protected UmbracoControl(UmbracoContext umbracoContext) + { + if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); + UmbracoContext = umbracoContext; + Umbraco = new UmbracoHelper(umbracoContext); + } - public UmbracoControl() - { - - } + /// + /// Empty constructor, uses Singleton to resolve the UmbracoContext + /// + protected UmbracoControl() + : this(UmbracoContext.Current) + { + } + + /// + /// Returns an UmbracoHelper object + /// + public UmbracoHelper Umbraco { get; private set; } + + public UmbracoContext UmbracoContext { get; private set; } - private UmbracoContext _umbracoContext; - protected UmbracoContext UmbracoContext - { - get { return _umbracoContext ?? (_umbracoContext = UmbracoContext.Current); } - } protected ApplicationContext ApplicationContext { get { return UmbracoContext.Application; } @@ -39,6 +54,18 @@ namespace Umbraco.Web.UI.Controls get { return ApplicationContext.Services; } } + private UrlHelper _url; + /// + /// Returns a UrlHelper + /// + /// + /// This URL helper is created without any route data and an empty request context + /// + public UrlHelper Url + { + get { return _url ?? (_url = new UrlHelper(new RequestContext(new HttpContextWrapper(Context), new RouteData()))); } + } + /// /// Returns the legacy SqlHelper /// diff --git a/src/Umbraco.Web/UI/Controls/UmbracoUserControl.cs b/src/Umbraco.Web/UI/Controls/UmbracoUserControl.cs new file mode 100644 index 0000000000..35e6cba498 --- /dev/null +++ b/src/Umbraco.Web/UI/Controls/UmbracoUserControl.cs @@ -0,0 +1,96 @@ +using System; +using System.Web; +using System.Web.Mvc; +using System.Web.Routing; +using System.Web.UI; +using Umbraco.Core; +using Umbraco.Core.Services; +using umbraco.DataLayer; + +namespace Umbraco.Web.UI.Controls +{ + /// + /// A base class for all Presentation UserControls to inherit from + /// + public abstract class UmbracoUserControl : UserControl + { + /// + /// Default constructor + /// + /// + protected UmbracoUserControl(UmbracoContext umbracoContext) + { + if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); + UmbracoContext = umbracoContext; + InstanceId = Guid.NewGuid(); + Umbraco = new UmbracoHelper(umbracoContext); + } + + /// + /// Empty constructor, uses Singleton to resolve the UmbracoContext + /// + protected UmbracoUserControl() + : this(UmbracoContext.Current) + { + } + + /// + /// Useful for debugging + /// + internal Guid InstanceId { get; private set; } + + /// + /// Returns an UmbracoHelper object + /// + public UmbracoHelper Umbraco { get; private set; } + + /// + /// Returns the current UmbracoContext + /// + public UmbracoContext UmbracoContext { get; private set; } + + /// + /// Returns the current ApplicationContext + /// + public ApplicationContext ApplicationContext + { + get { return UmbracoContext.Application; } + } + + /// + /// Returns a ServiceContext + /// + public ServiceContext Services + { + get { return ApplicationContext.Services; } + } + + /// + /// Returns a DatabaseContext + /// + public DatabaseContext DatabaseContext + { + get { return ApplicationContext.DatabaseContext; } + } + + private UrlHelper _url; + /// + /// Returns a UrlHelper + /// + /// + /// This URL helper is created without any route data and an empty request context + /// + public UrlHelper Url + { + get { return _url ?? (_url = new UrlHelper(new RequestContext(new HttpContextWrapper(Context), new RouteData()))); } + } + + /// + /// Returns the legacy SqlHelper + /// + protected ISqlHelper SqlHelper + { + get { return global::umbraco.BusinessLogic.Application.SqlHelper; } + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 6bd92e1940..8c9b6c282a 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -356,6 +356,7 @@ + ASPXCodeBehind diff --git a/src/Umbraco.Web/UmbracoUserControl.cs b/src/Umbraco.Web/UmbracoUserControl.cs index ac0a0dd60f..7b698139f4 100644 --- a/src/Umbraco.Web/UmbracoUserControl.cs +++ b/src/Umbraco.Web/UmbracoUserControl.cs @@ -11,77 +11,26 @@ namespace Umbraco.Web /// /// A base class for all Presentation UserControls to inherit from /// - public abstract class UmbracoUserControl : UserControl + [Obsolete("Use the Umbraco.Web.UI.Controls.UmbracoUserControl instead")] + public abstract class UmbracoUserControl : Umbraco.Web.UI.Controls.UmbracoUserControl { /// /// Default constructor /// /// protected UmbracoUserControl(UmbracoContext umbracoContext) + : base(umbracoContext) { - if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); - UmbracoContext = umbracoContext; - InstanceId = Guid.NewGuid(); - Umbraco = new UmbracoHelper(umbracoContext); + } /// /// Empty constructor, uses Singleton to resolve the UmbracoContext /// protected UmbracoUserControl() - : this(UmbracoContext.Current) + : base() { } - /// - /// Useful for debugging - /// - internal Guid InstanceId { get; private set; } - - /// - /// Returns an UmbracoHelper object - /// - public UmbracoHelper Umbraco { get; private set; } - - /// - /// Returns the current UmbracoContext - /// - public UmbracoContext UmbracoContext { get; private set; } - - /// - /// Returns the current ApplicationContext - /// - public ApplicationContext ApplicationContext - { - get { return UmbracoContext.Application; } - } - - /// - /// Returns a ServiceContext - /// - public ServiceContext Services - { - get { return ApplicationContext.Services; } - } - - /// - /// Returns a DatabaseContext - /// - public DatabaseContext DatabaseContext - { - get { return ApplicationContext.DatabaseContext; } - } - - private UrlHelper _url; - /// - /// Returns a UrlHelper - /// - /// - /// This URL helper is created without any route data and an empty request context - /// - public UrlHelper Url - { - get { return _url ?? (_url = new UrlHelper(new RequestContext(new HttpContextWrapper(Context), new RouteData()))); } - } } } \ No newline at end of file