using System; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Web.Actions; using Umbraco.Web.ContentApps; using Umbraco.Web.Dashboards; using Umbraco.Web.Editors; using Umbraco.Web.HealthCheck; using Umbraco.Web.Media.EmbedProviders; using Umbraco.Web.Mvc; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Search; using Umbraco.Web.Sections; using Umbraco.Web.Tour; using Umbraco.Web.Trees; using Current = Umbraco.Web.Composing.Current; // the namespace here is intentional - although defined in Umbraco.Web assembly, // this class should be visible when using Umbraco.Core.Components, alongside // Umbraco.Core's own CompositionExtensions class // ReSharper disable once CheckNamespace namespace Umbraco.Web { /// /// Provides extension methods to the class. /// public static class WebCompositionExtensions { #region Collection Builders /// /// Gets the filtered controller factories collection builder. /// /// The composition. /// public static FilteredControllerFactoryCollectionBuilder FilteredControllerFactory(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the back office tree collection builder /// /// /// public static TreeCollectionBuilder Trees(this Composition composition) => composition.WithCollectionBuilder(); #endregion #region Uniques /// /// Sets the content last chance finder. /// /// The type of the content last chance finder. /// The composition. public static void SetContentLastChanceFinder(this Composition composition) where T : IContentLastChanceFinder { composition.RegisterUnique(); } /// /// Sets the content last chance finder. /// /// The composition. /// A function creating a last chance finder. public static void SetContentLastChanceFinder(this Composition composition, Func factory) { composition.RegisterUnique(factory); } /// /// Sets the content last chance finder. /// /// The composition. /// A last chance finder. public static void SetContentLastChanceFinder(this Composition composition, IContentLastChanceFinder finder) { composition.RegisterUnique(_ => finder); } /// /// Sets the site domain helper. /// /// The type of the site domain helper. /// public static void SetSiteDomainHelper(this Composition composition) where T : ISiteDomainHelper { composition.RegisterUnique(); } /// /// Sets the site domain helper. /// /// The composition. /// A function creating a helper. public static void SetSiteDomainHelper(this Composition composition, Func factory) { composition.RegisterUnique(factory); } /// /// Sets the site domain helper. /// /// The composition. /// A helper. public static void SetSiteDomainHelper(this Composition composition, ISiteDomainHelper helper) { composition.RegisterUnique(_ => helper); } /// /// Sets the default controller for rendering template views. /// /// The type of the controller. /// The composition. /// The controller type is registered to the container by the composition. public static void SetDefaultRenderMvcController(this Composition composition) => composition.SetDefaultRenderMvcController(typeof(TController)); /// /// Sets the default controller for rendering template views. /// /// The composition. /// The type of the controller. /// The controller type is registered to the container by the composition. public static void SetDefaultRenderMvcController(this Composition composition, Type controllerType) { composition.OnCreatingFactory["Umbraco.Core.DefaultRenderMvcController"] = () => { // no need to register: all IRenderMvcController are registered //composition.Register(controllerType, Lifetime.Request); Current.DefaultRenderMvcControllerType = controllerType; }; } #endregion } }