using System; using Umbraco.Core.Cache; using Umbraco.Core.Dictionary; using Umbraco.Core.Composing; using Umbraco.Core.IO; 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 FileSystems /// /// Registers a filesystem. /// /// The type of the filesystem. /// The implementing type. /// The composition. /// The register. public static void RegisterFileSystem(this Composition composition) where TImplementing : FileSystemWrapper, TFileSystem where TFileSystem : class { composition.RegisterUnique(factory => { var fileSystems = factory.GetInstance(); var supporting = factory.GetInstance(); return fileSystems.GetFileSystem(supporting.For()); }); } /// /// Registers a filesystem. /// /// The type of the filesystem. /// The composition. /// The register. public static void RegisterFileSystem(this Composition composition) where TFileSystem : FileSystemWrapper { composition.RegisterUnique(factory => { var fileSystems = factory.GetInstance(); var supporting = factory.GetInstance(); return fileSystems.GetFileSystem(supporting.For()); }); } #endregion #region Collection Builders /// /// Gets the cache refreshers collection builder. /// /// The composition. public static CacheRefresherCollectionBuilder CacheRefreshers(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the mappers collection builder. /// /// The composition. public static MapperCollectionBuilder Mappers(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the package actions collection builder. /// /// The composition. internal static PackageActionCollectionBuilder PackageActions(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the data editor collection builder. /// /// The composition. public static DataEditorCollectionBuilder DataEditors(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the property value converters collection builder. /// /// The composition. public static PropertyValueConverterCollectionBuilder PropertyValueConverters(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the url segment providers collection builder. /// /// The composition. public static UrlSegmentProviderCollectionBuilder UrlSegmentProviders(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the validators collection builder. /// /// The composition. internal static ManifestValueValidatorCollectionBuilder Validators(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the post-migrations collection builder. /// /// The composition. internal static PostMigrationCollectionBuilder PostMigrations(this Composition composition) => composition.WithCollectionBuilder(); /// /// Gets the components collection builder. /// public static ComponentCollectionBuilder Components(this Composition composition) => composition.WithCollectionBuilder(); #endregion #region Uniques /// /// Sets the culture dictionary factory. /// /// The type of the factory. /// The composition. public static void SetCultureDictionaryFactory(this Composition composition) where T : ICultureDictionaryFactory { composition.RegisterUnique(); } /// /// Sets the culture dictionary factory. /// /// The composition. /// A function creating a culture dictionary factory. public static void SetCultureDictionaryFactory(this Composition composition, Func factory) { composition.RegisterUnique(factory); } /// /// Sets the culture dictionary factory. /// /// The composition. /// A factory. public static void SetCultureDictionaryFactory(this Composition composition, ICultureDictionaryFactory factory) { composition.RegisterUnique(_ => 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.RegisterUnique(); } /// /// 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.RegisterUnique(factory); } /// /// Sets the published content model factory. /// /// The composition. /// A published content model factory. public static void SetPublishedContentModelFactory(this Composition composition, IPublishedModelFactory factory) { composition.RegisterUnique(_ => factory); } /// /// Sets the server registrar. /// /// The type of the server registrar. /// The composition. public static void SetServerRegistrar(this Composition composition) where T : IServerRegistrar { composition.RegisterUnique(); } /// /// Sets the server registrar. /// /// The composition. /// A function creating a server registar. public static void SetServerRegistrar(this Composition composition, Func factory) { composition.RegisterUnique(factory); } /// /// Sets the server registrar. /// /// The composition. /// A server registrar. public static void SetServerRegistrar(this Composition composition, IServerRegistrar registrar) { composition.RegisterUnique(_ => registrar); } /// /// Sets the server messenger. /// /// The type of the server registrar. /// The composition. public static void SetServerMessenger(this Composition composition) where T : IServerMessenger { composition.RegisterUnique(); } /// /// Sets the server messenger. /// /// The composition. /// A function creating a server messenger. public static void SetServerMessenger(this Composition composition, Func factory) { composition.RegisterUnique(factory); } /// /// Sets the server messenger. /// /// The composition. /// A server messenger. public static void SetServerMessenger(this Composition composition, IServerMessenger registrar) { composition.RegisterUnique(_ => 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.RegisterUnique(); } /// /// Sets the short string helper. /// /// The composition. /// A function creating a short string helper. public static void SetShortStringHelper(this Composition composition, Func factory) { composition.RegisterUnique(factory); } /// /// Sets the short string helper. /// /// A composition. /// A short string helper. public static void SetShortStringHelper(this Composition composition, IShortStringHelper helper) { composition.RegisterUnique(_ => helper); } /// /// Sets the underlying media filesystem. /// /// A composition. /// A filesystem factory. public static void SetMediaFileSystem(this Composition composition, Func filesystemFactory) => composition.RegisterUniqueFor(filesystemFactory); /// /// Sets the underlying media filesystem. /// /// A composition. /// A filesystem factory. public static void SetMediaFileSystem(this Composition composition, Func filesystemFactory) => composition.RegisterUniqueFor(_ => filesystemFactory()); #endregion } }