From 96bcc74742d1cf2cb47b6d7a224c056e2820cf01 Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Thu, 3 Jan 2013 08:04:19 -0100 Subject: [PATCH] Adding UmbracoUserControl, which exposes the various contexts and the umbraco helper similar to the PluginController. --- src/Umbraco.Web/Umbraco.Web.csproj | 3 ++ src/Umbraco.Web/UmbracoUserControl.cs | 72 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/Umbraco.Web/UmbracoUserControl.cs diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index a635180419..3269f48e57 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -421,6 +421,9 @@ + + ASPXCodeBehind + diff --git a/src/Umbraco.Web/UmbracoUserControl.cs b/src/Umbraco.Web/UmbracoUserControl.cs new file mode 100644 index 0000000000..e9f3444483 --- /dev/null +++ b/src/Umbraco.Web/UmbracoUserControl.cs @@ -0,0 +1,72 @@ +using System; +using System.Web.UI; +using Umbraco.Core; +using Umbraco.Core.Services; + +namespace Umbraco.Web +{ + /// + /// 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; } + } + } +} \ No newline at end of file