using System; using LightInject; using Umbraco.Core.Composing; using Current = Umbraco.Web.Composing.Current; using Umbraco.Core.Macros; using Umbraco.Web.Editors; using Umbraco.Web.HealthCheck; using Umbraco.Web.Media; using Umbraco.Web.Mvc; using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web._Legacy.Actions; // 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.Core.Components { /// /// 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.Container.GetInstance(); /// /// Gets the content finders collection builder. /// /// The composition. /// public static ContentFinderCollectionBuilder ContentFinders(this Composition composition) => composition.Container.GetInstance(); /// /// Gets the editor validators collection builder. /// /// The composition. /// internal static EditorValidatorCollectionBuilder EditorValidators(this Composition composition) => composition.Container.GetInstance(); /// /// Gets the filtered controller factories collection builder. /// /// The composition. /// public static FilteredControllerFactoryCollectionBuilder FilderedControllerFactory(this Composition composition) => composition.Container.GetInstance(); /// /// Gets the health checks collection builder. /// /// The composition. public static HealthCheckCollectionBuilder HealthChecks(this Composition composition) => composition.Container.GetInstance(); /// /// Gets the url providers collection builder. /// /// The composition. internal static UrlProviderCollectionBuilder UrlProviders(this Composition composition) => composition.Container.GetInstance(); #endregion #region Singletons /// /// 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.Container.RegisterSingleton(); } /// /// 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.Container.RegisterSingleton(factory); } /// /// Sets the content last chance finder. /// /// The composition. /// A last chance finder. public static void SetContentLastChanceFinder(this Composition composition, IContentLastChanceFinder finder) { composition.Container.RegisterSingleton(_ => finder); } /// /// Sets the type of the default rendering controller. /// /// The type of the default rendering controller. /// The composition. public static void SetDefaultRenderMvcControllerType(this Composition composition) { Current.DefaultRenderMvcControllerType = typeof(T); } /// /// 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.Container.RegisterSingleton(); } /// /// Sets the published snapshot service. /// /// The composition. /// A function creating a published snapshot service. public static void SetPublishedSnapshotService(this Composition composition, Func factory) { composition.Container.RegisterSingleton(factory); } /// /// Sets the published snapshot service. /// /// The composition. /// A published snapshot service. public static void SetPublishedSnapshotService(this Composition composition, IPublishedSnapshotService service) { composition.Container.RegisterSingleton(_ => service); } /// /// Sets the site domain helper. /// /// The type of the site domain helper. /// public static void SetSiteDomainHelper(this Composition composition) where T : ISiteDomainHelper { composition.Container.RegisterSingleton(); } /// /// Sets the site domain helper. /// /// The composition. /// A function creating a helper. public static void SetSiteDomainHelper(this Composition composition, Func factory) { composition.Container.RegisterSingleton(factory); } /// /// Sets the site domain helper. /// /// The composition. /// A helper. public static void SetSiteDomainHelper(this Composition composition, ISiteDomainHelper helper) { composition.Container.RegisterSingleton(_ => helper); } #endregion } }