Files
Umbraco-CMS/src/Umbraco.Web/CompositionExtensions.cs

191 lines
7.7 KiB
C#
Raw Normal View History

using System;
2017-05-30 15:46:25 +02:00
using Umbraco.Core.Composing;
2017-05-30 18:13:11 +02:00
using Current = Umbraco.Web.Composing.Current;
using Umbraco.Web.Actions;
using Umbraco.Web.Editors;
using Umbraco.Web.HealthCheck;
using Umbraco.Web.Mvc;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.ContentApps;
using Umbraco.Web.Features;
// 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
{
/// <summary>
/// Provides extension methods to the <see cref="Composition"/> class.
/// </summary>
public static class WebCompositionExtensions
{
#region Collection Builders
/// <summary>
/// Gets the actions collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
/// <returns></returns>
internal static ActionCollectionBuilder Actions(this Composition composition)
2018-11-28 17:35:12 +01:00
=> composition.WithCollectionBuilder<ActionCollectionBuilder>();
2018-07-20 15:45:01 +02:00
/// <summary>
/// Gets the content apps collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
/// <returns></returns>
public static ContentAppDefinitionCollectionBuilder ContentApps(this Composition composition)
2018-11-28 17:35:12 +01:00
=> composition.WithCollectionBuilder<ContentAppDefinitionCollectionBuilder>();
/// <summary>
/// Gets the content finders collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
/// <returns></returns>
public static ContentFinderCollectionBuilder ContentFinders(this Composition composition)
2018-11-28 17:35:12 +01:00
=> composition.WithCollectionBuilder<ContentFinderCollectionBuilder>();
/// <summary>
/// Gets the editor validators collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
/// <returns></returns>
internal static EditorValidatorCollectionBuilder EditorValidators(this Composition composition)
2018-11-28 17:35:12 +01:00
=> composition.WithCollectionBuilder<EditorValidatorCollectionBuilder>();
/// <summary>
/// Gets the filtered controller factories collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
/// <returns></returns>
public static FilteredControllerFactoryCollectionBuilder FilderedControllerFactory(this Composition composition)
2018-11-28 17:35:12 +01:00
=> composition.WithCollectionBuilder<FilteredControllerFactoryCollectionBuilder>();
/// <summary>
/// Gets the health checks collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
public static HealthCheckCollectionBuilder HealthChecks(this Composition composition)
2018-11-28 17:35:12 +01:00
=> composition.WithCollectionBuilder<HealthCheckCollectionBuilder>();
/// <summary>
/// Gets the url providers collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
internal static UrlProviderCollectionBuilder UrlProviders(this Composition composition)
2018-11-28 17:35:12 +01:00
=> composition.WithCollectionBuilder<UrlProviderCollectionBuilder>();
#endregion
#region Singletons
/// <summary>
/// Sets the content last chance finder.
/// </summary>
/// <typeparam name="T">The type of the content last chance finder.</typeparam>
/// <param name="composition">The composition.</param>
public static void SetContentLastChanceFinder<T>(this Composition composition)
where T : IContentLastChanceFinder
{
2018-11-28 11:05:41 +01:00
composition.RegisterSingleton<IContentLastChanceFinder, T>();
}
/// <summary>
/// Sets the content last chance finder.
/// </summary>
/// <param name="composition">The composition.</param>
/// <param name="factory">A function creating a last chance finder.</param>
2018-11-28 11:05:41 +01:00
public static void SetContentLastChanceFinder(this Composition composition, Func<IFactory, IContentLastChanceFinder> factory)
{
2018-11-28 11:05:41 +01:00
composition.RegisterSingleton(factory);
}
/// <summary>
/// Sets the content last chance finder.
/// </summary>
/// <param name="composition">The composition.</param>
/// <param name="finder">A last chance finder.</param>
public static void SetContentLastChanceFinder(this Composition composition, IContentLastChanceFinder finder)
{
2018-11-28 11:05:41 +01:00
composition.RegisterSingleton(_ => finder);
}
/// <summary>
/// Sets the type of the default rendering controller.
/// </summary>
/// <typeparam name="T">The type of the default rendering controller.</typeparam>
/// <param name="composition">The composition.</param>
public static void SetDefaultRenderMvcControllerType<T>(this Composition composition)
{
2017-05-30 18:13:11 +02:00
Current.DefaultRenderMvcControllerType = typeof(T);
}
/// <summary>
2017-10-31 12:48:24 +01:00
/// Sets the published snapshot service.
/// </summary>
2017-10-31 12:48:24 +01:00
/// <typeparam name="T">The type of the published snapshot service.</typeparam>
/// <param name="composition">The composition.</param>
2017-10-31 12:48:24 +01:00
public static void SetPublishedSnapshotService<T>(this Composition composition)
where T : IPublishedSnapshotService
{
2018-11-28 11:05:41 +01:00
composition.RegisterSingleton<IPublishedSnapshotService, T>();
}
/// <summary>
2017-10-31 12:48:24 +01:00
/// Sets the published snapshot service.
/// </summary>
/// <param name="composition">The composition.</param>
2017-10-31 12:48:24 +01:00
/// <param name="factory">A function creating a published snapshot service.</param>
2018-11-28 11:05:41 +01:00
public static void SetPublishedSnapshotService(this Composition composition, Func<IFactory, IPublishedSnapshotService> factory)
{
2018-11-28 11:05:41 +01:00
composition.RegisterSingleton(factory);
}
/// <summary>
2017-10-31 12:48:24 +01:00
/// Sets the published snapshot service.
/// </summary>
/// <param name="composition">The composition.</param>
2017-10-31 12:48:24 +01:00
/// <param name="service">A published snapshot service.</param>
public static void SetPublishedSnapshotService(this Composition composition, IPublishedSnapshotService service)
{
2018-11-28 11:05:41 +01:00
composition.RegisterSingleton(_ => service);
}
/// <summary>
/// Sets the site domain helper.
/// </summary>
/// <typeparam name="T">The type of the site domain helper.</typeparam>
/// <param name="composition"></param>
public static void SetSiteDomainHelper<T>(this Composition composition)
where T : ISiteDomainHelper
{
2018-11-28 11:05:41 +01:00
composition.RegisterSingleton<ISiteDomainHelper, T>();
}
/// <summary>
/// Sets the site domain helper.
/// </summary>
/// <param name="composition">The composition.</param>
/// <param name="factory">A function creating a helper.</param>
2018-11-28 11:05:41 +01:00
public static void SetSiteDomainHelper(this Composition composition, Func<IFactory, ISiteDomainHelper> factory)
{
2018-11-28 11:05:41 +01:00
composition.RegisterSingleton(factory);
}
/// <summary>
/// Sets the site domain helper.
/// </summary>
/// <param name="composition">The composition.</param>
/// <param name="helper">A helper.</param>
public static void SetSiteDomainHelper(this Composition composition, ISiteDomainHelper helper)
{
2018-11-28 11:05:41 +01:00
composition.RegisterSingleton(_ => helper);
}
#endregion
}
}