Files
Umbraco-CMS/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs

183 lines
8.2 KiB
C#
Raw Normal View History

2019-01-03 21:00:28 +01:00
using System;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing.CompositionExtensions;
2019-01-03 21:00:28 +01:00
using Umbraco.Core.Configuration;
2020-03-13 20:37:10 +01:00
using Umbraco.Core.Configuration.Grid;
2019-01-03 21:00:28 +01:00
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Dashboards;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Hosting;
2019-01-03 21:00:28 +01:00
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
using Umbraco.Core.Migrations;
using Umbraco.Core.Migrations.Install;
2019-02-13 09:53:17 +01:00
using Umbraco.Core.Migrations.PostMigrations;
2019-01-03 21:00:28 +01:00
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.Validators;
using Umbraco.Core.Scoping;
using Umbraco.Core.Serialization;
2019-01-03 21:00:28 +01:00
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
2019-01-03 21:00:28 +01:00
using Umbraco.Core.Strings;
using Umbraco.Core.Sync;
using Umbraco.Web;
using Umbraco.Web.Install;
using Umbraco.Web.Migrations.PostMigrations;
using Umbraco.Web.Models.PublishedContent;
using Umbraco.Web.PropertyEditors;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Services;
using Umbraco.Web.Trees;
2019-01-03 21:00:28 +01:00
using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator;
namespace Umbraco.Core.Runtime
{
2019-03-05 08:47:31 +01:00
// core's initial composer composes before all core composers
[ComposeBefore(typeof(ICoreComposer))]
public class CoreInitialComposer : ComponentComposer<CoreInitialComponent>
2019-01-03 21:00:28 +01:00
{
public override void Compose(Composition composition)
2019-01-03 21:00:28 +01:00
{
base.Compose(composition);
2019-01-03 21:00:28 +01:00
// composers
composition
.ComposeRepositories()
.ComposeServices()
.ComposeCoreMappingProfiles()
.ComposeFileSystems();
// register persistence mappers - required by database factory so needs to be done here
// means the only place the collection can be modified is in a runtime - afterwards it
// has been frozen and it is too late
composition.Mappers().AddCoreMappers();
2019-01-03 21:00:28 +01:00
// register the scope provider
composition.RegisterUnique<ScopeProvider>(); // implements both IScopeProvider and IScopeAccessor
composition.RegisterUnique<IScopeProvider>(f => f.GetInstance<ScopeProvider>());
composition.RegisterUnique<IScopeAccessor>(f => f.GetInstance<ScopeProvider>());
composition.RegisterUnique<IJsonSerializer, JsonNetSerializer>();
composition.RegisterUnique<IMenuItemCollectionFactory, MenuItemCollectionFactory>();
composition.RegisterUnique<InstallStatusTracker>();
2019-01-03 21:00:28 +01:00
// register database builder
// *not* a singleton, don't want to keep it around
composition.Register<DatabaseBuilder>();
// register manifest parser, will be injected in collection builders where needed
2019-11-06 13:35:34 +01:00
composition.RegisterUnique<IManifestParser, ManifestParser>();
2019-01-03 21:00:28 +01:00
// register our predefined validators
composition.ManifestValueValidators()
2019-01-03 21:00:28 +01:00
.Add<RequiredValidator>()
.Add<RegexValidator>()
.Add<DelimitedValueValidator>()
.Add<EmailValidator>()
.Add<IntegerValidator>()
.Add<DecimalValidator>();
// register the manifest filter collection builder (collection is empty by default)
composition.ManifestFilters();
2019-01-03 21:00:28 +01:00
// properties and parameters derive from data editors
composition.DataEditors()
2019-01-03 21:00:28 +01:00
.Add(() => composition.TypeLoader.GetDataEditors());
composition.MediaUrlGenerators()
.Add<FileUploadPropertyEditor>()
.Add<ImageCropperPropertyEditor>();
2019-01-03 21:00:28 +01:00
composition.RegisterUnique<PropertyEditorCollection>();
composition.RegisterUnique<ParameterEditorCollection>();
// Used to determine if a datatype/editor should be storing/tracking
// references to media item/s
composition.DataValueReferenceFactories();
2019-01-03 21:00:28 +01:00
// register a server registrar, by default it's the db registrar
composition.RegisterUnique<IServerRegistrar>(f =>
{
var globalSettings = f.GetInstance<IGlobalSettings>();
// TODO: we still register the full IServerMessenger because
// even on 1 single server we can have 2 concurrent app domains
var singleServer = globalSettings.DisableElectionForSingleServer;
return singleServer
? (IServerRegistrar) new SingleServerRegistrar(f.GetInstance<IRuntimeState>())
: new DatabaseServerRegistrar(
new Lazy<IServerRegistrationService>(f.GetInstance<IServerRegistrationService>),
new DatabaseServerRegistrarOptions());
2019-01-03 21:00:28 +01:00
});
// by default we'll use the database server messenger with default options (no callbacks),
// this will be overridden by the db thing in the corresponding components in the web
// project
2019-01-03 21:00:28 +01:00
composition.RegisterUnique<IServerMessenger>(factory
=> new DatabaseServerMessenger(
factory.GetInstance<IMainDom>(),
2019-01-03 21:00:28 +01:00
factory.GetInstance<IScopeProvider>(),
factory.GetInstance<ISqlContext>(),
factory.GetInstance<IProfilingLogger>(),
factory.GetInstance<IServerRegistrar>(),
2019-11-19 08:52:39 +01:00
true, new DatabaseServerMessengerOptions(),
factory.GetInstance<IHostingEnvironment>(),
factory.GetInstance<CacheRefresherCollection>()
));
2019-01-03 21:00:28 +01:00
composition.CacheRefreshers()
2019-01-03 21:00:28 +01:00
.Add(() => composition.TypeLoader.GetCacheRefreshers());
composition.PackageActions()
2019-01-03 21:00:28 +01:00
.Add(() => composition.TypeLoader.GetPackageActions());
composition.PropertyValueConverters()
2019-01-03 21:00:28 +01:00
.Append(composition.TypeLoader.GetTypes<IPropertyValueConverter>());
composition.RegisterUnique<IPublishedContentTypeFactory, PublishedContentTypeFactory>();
composition.RegisterUnique<IShortStringHelper>(factory
=> new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetInstance<IRequestHandlerSettings>())));
2019-01-03 21:00:28 +01:00
composition.UrlSegmentProviders()
2019-01-03 21:00:28 +01:00
.Append<DefaultUrlSegmentProvider>();
composition.RegisterUnique<IMigrationBuilder>(factory => new MigrationBuilder(factory));
// by default, register a noop factory
composition.RegisterUnique<IPublishedModelFactory, NoopPublishedModelFactory>();
2019-02-13 09:53:17 +01:00
// by default
2019-02-13 09:53:17 +01:00
composition.RegisterUnique<IPublishedSnapshotRebuilder, PublishedSnapshotRebuilder>();
composition.SetCultureDictionaryFactory<DefaultCultureDictionaryFactory>();
composition.Register(f => f.GetInstance<ICultureDictionaryFactory>().CreateDictionary(), Lifetime.Singleton);
composition.RegisterUnique<UriUtility>();
// register the published snapshot accessor - the "current" published snapshot is in the umbraco context
composition.RegisterUnique<IPublishedSnapshotAccessor, UmbracoContextPublishedSnapshotAccessor>();
composition.RegisterUnique<IVariationContextAccessor, HybridVariationContextAccessor>();
composition.RegisterUnique<IDashboardService, DashboardService>();
// register core CMS dashboards and 3rd party types - will be ordered by weight attribute & merged with package.manifest dashboards
composition.Dashboards()
.Add(composition.TypeLoader.GetTypes<IDashboard>());
// will be injected in controllers when needed to invoke rest endpoints on Our
composition.RegisterUnique<IInstallationService, InstallationService>();
composition.RegisterUnique<IUpgradeService, UpgradeService>();
2020-03-13 20:37:10 +01:00
// Grid config is not a real config file as we know them
composition.RegisterUnique<IGridConfig, GridConfig>();
// Config manipulator
composition.RegisterUnique<IConfigManipulator, JsonConfigManipulator>();
2019-01-03 21:00:28 +01:00
}
}
}