using System; using System.Web.Mvc; using System.Web.UI; using Umbraco.Core.Cache; using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Web.Composing; namespace Umbraco.Web.UI.Controls { /// /// A control that exposes the helpful Umbraco context objects /// public abstract class UmbracoControl : Control { private UrlHelper _url; protected UmbracoControl(UmbracoContext umbracoContext, ServiceContext services) { UmbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext)); Umbraco = new UmbracoHelper(umbracoContext, services); // todo inject somehow Logger = Current.Logger; ProfilingLogger = Current.ProfilingLogger; Services = Current.Services; } /// /// Empty constructor, uses Singleton to resolve the UmbracoContext. /// protected UmbracoControl() : this(Current.UmbracoContext, Current.Services) { } /// /// Returns an UmbracoHelper object /// public UmbracoHelper Umbraco { get; } /// /// Gets the logger. /// public ILogger Logger { get; } /// /// Gets the profiling logger. /// public IProfilingLogger ProfilingLogger { get; } /// /// Gets the Umbraco context. /// public UmbracoContext UmbracoContext { get; } /// /// Gets the services context. /// protected ServiceContext Services { get; } /// /// Gets a Url helper. /// /// This URL helper is created without any route data and an empty request context. public UrlHelper Url => _url ?? (_url = new UrlHelper(Context.Request.RequestContext)); } }