2016-10-07 14:34:55 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using Umbraco.Core.Cache;
|
|
|
|
|
|
using Umbraco.Core.Dictionary;
|
2017-05-30 15:46:25 +02:00
|
|
|
|
using Umbraco.Core.Composing;
|
2018-11-29 10:35:16 +01:00
|
|
|
|
using Umbraco.Core.IO;
|
2017-12-18 18:26:32 +01:00
|
|
|
|
using Umbraco.Core.Migrations;
|
2016-10-07 14:34:55 +02:00
|
|
|
|
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
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Provides extension methods to the <see cref="Composition"/> class.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class CompositionExtensions
|
|
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
#region FileSystems
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Registers a filesystem.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TFileSystem">The type of the filesystem.</typeparam>
|
|
|
|
|
|
/// <typeparam name="TImplementing">The implementing type.</typeparam>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="supportingFileSystemFactory">A factory method creating the supporting filesystem.</param>
|
|
|
|
|
|
/// <returns>The register.</returns>
|
|
|
|
|
|
public static void RegisterFileSystem<TFileSystem, TImplementing>(this Composition composition, Func<IFactory, IFileSystem> supportingFileSystemFactory)
|
|
|
|
|
|
where TImplementing : FileSystemWrapper, TFileSystem
|
|
|
|
|
|
{
|
|
|
|
|
|
composition.RegisterUnique<TFileSystem>(factory =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var fileSystems = factory.GetInstance<FileSystems>();
|
|
|
|
|
|
return fileSystems.GetFileSystem<TImplementing>(supportingFileSystemFactory(factory));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Registers a filesystem.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TFileSystem">The type of the filesystem.</typeparam>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="supportingFileSystemFactory">A factory method creating the supporting filesystem.</param>
|
|
|
|
|
|
/// <returns>The register.</returns>
|
|
|
|
|
|
public static void RegisterFileSystem<TFileSystem>(this Composition composition, Func<IFactory, IFileSystem> supportingFileSystemFactory)
|
|
|
|
|
|
where TFileSystem : FileSystemWrapper
|
|
|
|
|
|
{
|
|
|
|
|
|
composition.RegisterUnique(factory =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var fileSystems = factory.GetInstance<FileSystems>();
|
|
|
|
|
|
return fileSystems.GetFileSystem<TFileSystem>(supportingFileSystemFactory(factory));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
#region Collection Builders
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the cache refreshers collection builder.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
public static CacheRefresherCollectionBuilder CacheRefreshers(this Composition composition)
|
2018-11-28 17:35:12 +01:00
|
|
|
|
=> composition.WithCollectionBuilder<CacheRefresherCollectionBuilder>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the mappers collection builder.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
public static MapperCollectionBuilder Mappers(this Composition composition)
|
2018-11-28 17:35:12 +01:00
|
|
|
|
=> composition.WithCollectionBuilder<MapperCollectionBuilder>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the package actions collection builder.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
internal static PackageActionCollectionBuilder PackageActions(this Composition composition)
|
2018-11-28 17:35:12 +01:00
|
|
|
|
=> composition.WithCollectionBuilder<PackageActionCollectionBuilder>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-02-16 12:00:45 +01:00
|
|
|
|
/// Gets the data editor collection builder.
|
2016-10-07 14:34:55 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
2018-02-16 12:00:45 +01:00
|
|
|
|
public static DataEditorCollectionBuilder DataEditors(this Composition composition)
|
2018-11-28 17:35:12 +01:00
|
|
|
|
=> composition.WithCollectionBuilder<DataEditorCollectionBuilder>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the property value converters collection builder.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
public static PropertyValueConverterCollectionBuilder PropertyValueConverters(this Composition composition)
|
2018-11-28 17:35:12 +01:00
|
|
|
|
=> composition.WithCollectionBuilder<PropertyValueConverterCollectionBuilder>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the url segment providers collection builder.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
public static UrlSegmentProviderCollectionBuilder UrlSegmentProviders(this Composition composition)
|
2018-11-28 17:35:12 +01:00
|
|
|
|
=> composition.WithCollectionBuilder<UrlSegmentProviderCollectionBuilder>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the validators collection builder.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
2018-03-16 09:06:44 +01:00
|
|
|
|
internal static ManifestValueValidatorCollectionBuilder Validators(this Composition composition)
|
2018-11-28 17:35:12 +01:00
|
|
|
|
=> composition.WithCollectionBuilder<ManifestValueValidatorCollectionBuilder>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
|
2017-12-22 12:29:56 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the post-migrations collection builder.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
internal static PostMigrationCollectionBuilder PostMigrations(this Composition composition)
|
2018-11-28 17:35:12 +01:00
|
|
|
|
=> composition.WithCollectionBuilder<PostMigrationCollectionBuilder>();
|
2017-12-22 12:29:56 +01:00
|
|
|
|
|
2019-01-03 10:36:00 +01:00
|
|
|
|
/// <summary>
|
2019-01-03 21:00:28 +01:00
|
|
|
|
/// Gets the components collection builder.
|
2019-01-03 10:36:00 +01:00
|
|
|
|
/// </summary>
|
2019-01-03 21:00:28 +01:00
|
|
|
|
public static ComponentCollectionBuilder Components(this Composition composition)
|
|
|
|
|
|
=> composition.WithCollectionBuilder<ComponentCollectionBuilder>();
|
2019-01-03 10:36:00 +01:00
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2018-11-29 10:35:16 +01:00
|
|
|
|
#region Uniques
|
2016-10-07 14:34:55 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the culture dictionary factory.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T">The type of the factory.</typeparam>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
public static void SetCultureDictionaryFactory<T>(this Composition composition)
|
|
|
|
|
|
where T : ICultureDictionaryFactory
|
|
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<ICultureDictionaryFactory, T>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the culture dictionary factory.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="factory">A function creating a culture dictionary factory.</param>
|
2018-11-28 11:05:41 +01:00
|
|
|
|
public static void SetCultureDictionaryFactory(this Composition composition, Func<IFactory, ICultureDictionaryFactory> factory)
|
2016-10-07 14:34:55 +02:00
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique(factory);
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the culture dictionary factory.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="factory">A factory.</param>
|
|
|
|
|
|
public static void SetCultureDictionaryFactory(this Composition composition, ICultureDictionaryFactory factory)
|
|
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique(_ => factory);
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the published content model factory.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T">The type of the factory.</typeparam>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
public static void SetPublishedContentModelFactory<T>(this Composition composition)
|
2017-09-26 14:57:50 +02:00
|
|
|
|
where T : IPublishedModelFactory
|
2016-10-07 14:34:55 +02:00
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<IPublishedModelFactory, T>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the published content model factory.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="factory">A function creating a published content model factory.</param>
|
2018-11-28 11:05:41 +01:00
|
|
|
|
public static void SetPublishedContentModelFactory(this Composition composition, Func<IFactory, IPublishedModelFactory> factory)
|
2016-10-07 14:34:55 +02:00
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique(factory);
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the published content model factory.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="factory">A published content model factory.</param>
|
2017-09-26 14:57:50 +02:00
|
|
|
|
public static void SetPublishedContentModelFactory(this Composition composition, IPublishedModelFactory factory)
|
2016-10-07 14:34:55 +02:00
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique(_ => factory);
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the server registrar.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T">The type of the server registrar.</typeparam>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
public static void SetServerRegistrar<T>(this Composition composition)
|
|
|
|
|
|
where T : IServerRegistrar
|
|
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<IServerRegistrar, T>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the server registrar.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="factory">A function creating a server registar.</param>
|
2018-11-28 11:05:41 +01:00
|
|
|
|
public static void SetServerRegistrar(this Composition composition, Func<IFactory, IServerRegistrar> factory)
|
2016-10-07 14:34:55 +02:00
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique(factory);
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the server registrar.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="registrar">A server registrar.</param>
|
|
|
|
|
|
public static void SetServerRegistrar(this Composition composition, IServerRegistrar registrar)
|
|
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique(_ => registrar);
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the server messenger.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T">The type of the server registrar.</typeparam>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
public static void SetServerMessenger<T>(this Composition composition)
|
|
|
|
|
|
where T : IServerMessenger
|
|
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<IServerMessenger, T>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the server messenger.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="factory">A function creating a server messenger.</param>
|
2018-11-28 11:05:41 +01:00
|
|
|
|
public static void SetServerMessenger(this Composition composition, Func<IFactory, IServerMessenger> factory)
|
2016-10-07 14:34:55 +02:00
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique(factory);
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the server messenger.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="registrar">A server messenger.</param>
|
|
|
|
|
|
public static void SetServerMessenger(this Composition composition, IServerMessenger registrar)
|
|
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique(_ => registrar);
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the short string helper.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T">The type of the short string helper.</typeparam>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
public static void SetShortStringHelper<T>(this Composition composition)
|
|
|
|
|
|
where T : IShortStringHelper
|
|
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<IShortStringHelper, T>();
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the short string helper.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">The composition.</param>
|
|
|
|
|
|
/// <param name="factory">A function creating a short string helper.</param>
|
2018-11-28 11:05:41 +01:00
|
|
|
|
public static void SetShortStringHelper(this Composition composition, Func<IFactory, IShortStringHelper> factory)
|
2016-10-07 14:34:55 +02:00
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique(factory);
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets the short string helper.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="composition">A composition.</param>
|
|
|
|
|
|
/// <param name="helper">A short string helper.</param>
|
|
|
|
|
|
public static void SetShortStringHelper(this Composition composition, IShortStringHelper helper)
|
|
|
|
|
|
{
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique(_ => helper);
|
2016-10-07 14:34:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|