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