using System;
using System.Runtime.CompilerServices;
using LightInject;
using Umbraco.Core.Cache;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Composing;
using Umbraco.Core.Migrations;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Strings;
using Umbraco.Core.Sync;
using Umbraco.Core._Legacy.PackageActions;
namespace Umbraco.Core.Components
{
///
/// Provides extension methods to the class.
///
public static class CompositionExtensions
{
#region Collection Builders
///
/// Gets the cache refreshers collection builder.
///
/// The composition.
public static CacheRefresherCollectionBuilder CacheRefreshers(this Composition composition)
=> composition.Container.GetInstance();
///
/// Gets the mappers collection builder.
///
/// The composition.
public static MapperCollectionBuilder Mappers(this Composition composition)
=> composition.Container.GetInstance();
///
/// Gets the package actions collection builder.
///
/// The composition.
internal static PackageActionCollectionBuilder PackageActions(this Composition composition)
=> composition.Container.GetInstance();
///
/// Gets the data editor collection builder.
///
/// The composition.
public static DataEditorCollectionBuilder DataEditors(this Composition composition)
=> composition.Container.GetInstance();
///
/// Gets the property value converters collection builder.
///
/// The composition.
public static PropertyValueConverterCollectionBuilder PropertyValueConverters(this Composition composition)
=> composition.Container.GetInstance();
///
/// Gets the url segment providers collection builder.
///
/// The composition.
public static UrlSegmentProviderCollectionBuilder UrlSegmentProviders(this Composition composition)
=> composition.Container.GetInstance();
///
/// Gets the validators collection builder.
///
/// The composition.
internal static ManifestValidatorCollectionBuilder Validators(this Composition composition)
=> composition.Container.GetInstance();
///
/// Gets the post-migrations collection builder.
///
/// The composition.
internal static PostMigrationCollectionBuilder PostMigrations(this Composition composition)
=> composition.Container.GetInstance();
#endregion
#region Singleton
///
/// Sets the culture dictionary factory.
///
/// The type of the factory.
/// The composition.
public static void SetCultureDictionaryFactory(this Composition composition)
where T : ICultureDictionaryFactory
{
composition.Container.RegisterSingleton();
}
///
/// Sets the culture dictionary factory.
///
/// The composition.
/// A function creating a culture dictionary factory.
public static void SetCultureDictionaryFactory(this Composition composition, Func factory)
{
composition.Container.RegisterSingleton(factory);
}
///
/// Sets the culture dictionary factory.
///
/// The composition.
/// A factory.
public static void SetCultureDictionaryFactory(this Composition composition, ICultureDictionaryFactory factory)
{
composition.Container.RegisterSingleton(_ => factory);
}
///
/// Sets the published content model factory.
///
/// The type of the factory.
/// The composition.
public static void SetPublishedContentModelFactory(this Composition composition)
where T : IPublishedModelFactory
{
composition.Container.RegisterSingleton();
}
///
/// Sets the published content model factory.
///
/// The composition.
/// A function creating a published content model factory.
public static void SetPublishedContentModelFactory(this Composition composition, Func factory)
{
composition.Container.RegisterSingleton(factory);
}
///
/// Sets the published content model factory.
///
/// The composition.
/// A published content model factory.
public static void SetPublishedContentModelFactory(this Composition composition, IPublishedModelFactory factory)
{
composition.Container.RegisterSingleton(_ => factory);
}
///
/// Sets the server registrar.
///
/// The type of the server registrar.
/// The composition.
public static void SetServerRegistrar(this Composition composition)
where T : IServerRegistrar
{
composition.Container.RegisterSingleton();
}
///
/// Sets the server registrar.
///
/// The composition.
/// A function creating a server registar.
public static void SetServerRegistrar(this Composition composition, Func factory)
{
composition.Container.RegisterSingleton(factory);
}
///
/// Sets the server registrar.
///
/// The composition.
/// A server registrar.
public static void SetServerRegistrar(this Composition composition, IServerRegistrar registrar)
{
composition.Container.RegisterSingleton(_ => registrar);
}
///
/// Sets the server messenger.
///
/// The type of the server registrar.
/// The composition.
public static void SetServerMessenger(this Composition composition)
where T : IServerMessenger
{
composition.Container.RegisterSingleton();
}
///
/// Sets the server messenger.
///
/// The composition.
/// A function creating a server messenger.
public static void SetServerMessenger(this Composition composition, Func factory)
{
composition.Container.RegisterSingleton(factory);
}
///
/// Sets the server messenger.
///
/// The composition.
/// A server messenger.
public static void SetServerMessenger(this Composition composition, IServerMessenger registrar)
{
composition.Container.RegisterSingleton(_ => registrar);
}
///
/// Sets the short string helper.
///
/// The type of the short string helper.
/// The composition.
public static void SetShortStringHelper(this Composition composition)
where T : IShortStringHelper
{
composition.Container.RegisterSingleton();
}
///
/// Sets the short string helper.
///
/// The composition.
/// A function creating a short string helper.
public static void SetShortStringHelper(this Composition composition, Func factory)
{
composition.Container.RegisterSingleton(factory);
}
///
/// Sets the short string helper.
///
/// A composition.
/// A short string helper.
public static void SetShortStringHelper(this Composition composition, IShortStringHelper helper)
{
composition.Container.RegisterSingleton(_ => helper);
}
#endregion
}
}