using System; using Umbraco.Core.Components; 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.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 actions collection builder. /// /// The composition. /// internal static ActionCollectionBuilder Actions(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the content apps collection builder. /// /// The composition. /// public static ContentAppFactoryCollectionBuilder ContentApps(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the content finders collection builder. /// /// The composition. /// public static ContentFinderCollectionBuilder ContentFinders(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the editor validators collection builder. /// /// The composition. /// internal static EditorValidatorCollectionBuilder EditorValidators(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the filtered controller factories collection builder. /// /// The composition. /// public static FilteredControllerFactoryCollectionBuilder FilderedControllerFactory(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the health checks collection builder. /// /// The composition. public static HealthCheckCollectionBuilder HealthChecks(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the TourFilters collection builder. /// public static TourFilterCollectionBuilder TourFilters(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the url providers collection builder. /// /// The composition. public static UrlProviderCollectionBuilder UrlProviders(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the backoffice sections/applications collection builder. /// /// The composition. public static BackOfficeSectionCollectionBuilder Sections(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the backoffice dashboards collection builder. /// /// The composition. public static DashboardCollectionBuilder Dashboards(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the backoffice OEmbed Providers collection builder. /// /// The composition. public static EmbedProvidersCollectionBuilder OEmbedProviders(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 published snapshot service. /// /// The type of the published snapshot service. /// The composition. public static void SetPublishedSnapshotService(this Composition composition) where T : IPublishedSnapshotService { composition.RegisterUnique(); } /// /// Sets the published snapshot service. /// /// The composition. /// A function creating a published snapshot service. public static void SetPublishedSnapshotService(this Composition composition, Func factory) { composition.RegisterUnique(factory); } /// /// Sets the published snapshot service. /// /// The composition. /// A published snapshot service. public static void SetPublishedSnapshotService(this Composition composition, IPublishedSnapshotService service) { composition.RegisterUnique(_ => service); } /// /// 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 } }