using System; using System.Web; using System.Web.Mvc; using Microsoft.Owin; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Web.Security; namespace Umbraco.Web.Mvc { /// /// A base controller class containing all of the Umbraco objects as properties that a developer requires /// public abstract class UmbracoController : Controller { protected UmbracoController(UmbracoContext umbracoContext) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); UmbracoContext = umbracoContext; } protected UmbracoController(UmbracoContext umbracoContext, UmbracoHelper umbracoHelper) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); if (umbracoHelper == null) throw new ArgumentNullException("umbracoHelper"); UmbracoContext = umbracoContext; _umbraco = umbracoHelper; } protected UmbracoController() : this(UmbracoContext.Current) { } protected IOwinContext OwinContext { get { return Request.GetOwinContext(); } } private UmbracoHelper _umbraco; /// /// Returns the MemberHelper instance /// public MembershipHelper Members { get { return Umbraco.MembershipHelper; } } /// /// Returns an UmbracoHelper object /// public virtual UmbracoHelper Umbraco { get { return _umbraco ?? (_umbraco = new UmbracoHelper(UmbracoContext)); } } /// /// Returns an ILogger /// public ILogger Logger { get { return ProfilingLogger.Logger; } } /// /// Returns a ProfilingLogger /// public virtual ProfilingLogger ProfilingLogger { get { return UmbracoContext.Application.ProfilingLogger; } } /// /// Returns the current UmbracoContext /// public virtual UmbracoContext UmbracoContext { get; private set; } /// /// Returns the current ApplicationContext /// public virtual 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; } } /// /// Returns the WebSecurity instance /// public virtual WebSecurity Security { get { return UmbracoContext.Security; } } } }