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.Web.Security; 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); _membershipHelper = new MembershipHelper(umbracoContext); } /// /// Empty constructor, uses Singleton to resolve the UmbracoContext /// protected UmbracoUserControl() : this(UmbracoContext.Current) { } private readonly MembershipHelper _membershipHelper; /// /// Useful for debugging /// internal Guid InstanceId { get; private set; } /// /// Returns an UmbracoHelper object /// public UmbracoHelper Umbraco { get; private set; } /// /// Returns the MemberHelper instance /// public MembershipHelper Members { get { return _membershipHelper; } } /// /// Returns the current WebSecurity instance /// public WebSecurity Security { get { return UmbracoContext.Security; } } /// /// 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; } } } }