using System; using System.Web; using System.Web.Mvc; using LightInject; using Microsoft.Owin; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Core.Services; using Umbraco.Web.Security; namespace Umbraco.Web.Mvc { /// /// Provides a base class for Umbraco controllers. /// public abstract class UmbracoController : Controller { private UmbracoHelper _umbracoHelper; // for debugging purposes internal Guid InstanceId { get; } = Guid.NewGuid(); // note // properties marked as [Inject] below will be property-injected (vs constructor-injected) in // order to keep the constuctor as light as possible, so that ppl implementing eg a SurfaceController // don't need to implement complex constructors + need to refactor them each time we change ours. // this means that these properties have a setter. // what can go wrong? /// /// Gets or sets the Umbraco context. /// [Inject] public virtual IGlobalSettings GlobalSettings { get; set; } /// /// Gets or sets the Umbraco context. /// [Inject] public virtual UmbracoContext UmbracoContext { get; set; } /// /// Gets or sets the database context. /// [Inject] public IUmbracoDatabaseFactory DatabaseFactory { get; set; } /// /// Gets or sets the services context. /// [Inject] public ServiceContext Services { get; set; } /// /// Gets or sets the application cache. /// [Inject] public CacheHelper ApplicationCache { get; set; } /// /// Gets or sets the logger. /// [Inject] public ILogger Logger { get; set; } /// /// Gets or sets the profiling logger. /// [Inject] public ProfilingLogger ProfilingLogger { get; set; } protected IOwinContext OwinContext => Request.GetOwinContext(); /// /// Gets the membership helper. /// public MembershipHelper Members => Umbraco.MembershipHelper; /// /// Gets the Umbraco helper. /// public UmbracoHelper Umbraco => _umbracoHelper ?? (_umbracoHelper = new UmbracoHelper(UmbracoContext, Services, ApplicationCache)); /// /// Gets the web security helper. /// public virtual WebSecurity Security => UmbracoContext.Security; } }