Files
Umbraco-CMS/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs

144 lines
6.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Configuration;
using AutoMapper;
using Umbraco.Core.Cache;
using Umbraco.Core.Components;
2017-05-30 15:46:25 +02:00
using Umbraco.Core.Composing;
2018-07-20 09:49:05 +02:00
using Umbraco.Core.Composing.Composers;
2017-12-28 09:27:57 +01:00
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
2018-06-20 10:49:12 +02:00
using Umbraco.Core.IO.MediaPathSchemes;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
using Umbraco.Core.Migrations;
using Umbraco.Core.Migrations.Install;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence;
2018-11-27 10:37:33 +01:00
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.PropertyEditors;
2018-01-20 12:09:15 +01:00
using Umbraco.Core.PropertyEditors.Validators;
2017-05-12 14:49:44 +02:00
using Umbraco.Core.Scoping;
using Umbraco.Core.Services;
using Umbraco.Core.Strings;
using Umbraco.Core.Sync;
using Umbraco.Core._Legacy.PackageActions;
2018-01-20 12:09:15 +01:00
using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator;
2017-12-28 09:27:57 +01:00
namespace Umbraco.Core.Runtime
{
public class CoreRuntimeComponent : UmbracoComponentBase, IRuntimeComponent
{
public override void Compose(Composition composition)
{
base.Compose(composition);
2018-07-20 09:49:05 +02:00
// composers
2018-11-27 10:37:33 +01:00
composition
.ComposeConfiguration()
.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
2018-11-28 17:35:12 +01:00
composition.WithCollectionBuilder<MapperCollectionBuilder>().AddCoreMappers();
2018-11-27 10:37:33 +01:00
// register the scope provider
2018-11-29 10:35:16 +01:00
composition.RegisterUnique<ScopeProvider>(); // implements both IScopeProvider and IScopeAccessor
composition.RegisterUnique<IScopeProvider>(f => f.GetInstance<ScopeProvider>());
composition.RegisterUnique<IScopeAccessor>(f => f.GetInstance<ScopeProvider>());
2016-11-29 11:31:38 +01:00
// register database builder
// *not* a singleton, don't want to keep it around
2018-11-28 11:05:41 +01:00
composition.Register<DatabaseBuilder>();
2016-11-29 11:31:38 +01:00
2018-01-20 12:09:15 +01:00
// register manifest parser, will be injected in collection builders where needed
2018-11-29 10:35:16 +01:00
composition.RegisterUnique<ManifestParser>();
// register our predefined validators
2018-11-28 17:35:12 +01:00
composition.WithCollectionBuilder<ManifestValueValidatorCollectionBuilder>()
2018-03-16 09:06:44 +01:00
.Add<RequiredValidator>()
.Add<RegexValidator>()
2018-03-16 09:06:44 +01:00
.Add<DelimitedValueValidator>()
.Add<EmailValidator>()
.Add<IntegerValidator>()
.Add<DecimalValidator>();
2018-02-16 12:00:45 +01:00
// properties and parameters derive from data editors
2018-11-28 17:35:12 +01:00
composition.WithCollectionBuilder<DataEditorCollectionBuilder>()
2018-11-28 11:05:41 +01:00
.Add(() => composition.TypeLoader.GetDataEditors());
2018-11-29 10:35:16 +01:00
composition.RegisterUnique<PropertyEditorCollection>();
composition.RegisterUnique<ParameterEditorCollection>();
2018-01-26 17:55:20 +01:00
2018-11-28 16:57:01 +01:00
// register a server registrar, by default it's the db registrar
2018-11-29 10:35:16 +01:00
composition.RegisterUnique<IServerRegistrar>(f =>
{
if ("true".InvariantEquals(ConfigurationManager.AppSettings["umbracoDisableElectionForSingleServer"]))
return new SingleServerRegistrar(f.GetInstance<IRuntimeState>());
return new DatabaseServerRegistrar(
new Lazy<IServerRegistrationService>(f.GetInstance<IServerRegistrationService>),
new DatabaseServerRegistrarOptions());
});
// by default we'll use the database server messenger with default options (no callbacks),
// this will be overridden by either the legacy thing or the db thing in the corresponding
// components in the web project - fixme - should obsolete the legacy thing
2018-11-29 10:35:16 +01:00
composition.RegisterUnique<IServerMessenger>(factory
=> new DatabaseServerMessenger(
factory.GetInstance<IRuntimeState>(),
2017-05-12 14:49:44 +02:00
factory.GetInstance<IScopeProvider>(),
2017-09-22 18:28:21 +02:00
factory.GetInstance<ISqlContext>(),
2018-11-27 10:37:33 +01:00
factory.GetInstance<IProfilingLogger>(),
factory.GetInstance<IGlobalSettings>(),
true, new DatabaseServerMessengerOptions()));
2018-11-28 17:35:12 +01:00
composition.WithCollectionBuilder<CacheRefresherCollectionBuilder>()
2018-11-28 11:05:41 +01:00
.Add(() => composition.TypeLoader.GetCacheRefreshers());
2018-11-28 17:35:12 +01:00
composition.WithCollectionBuilder<PackageActionCollectionBuilder>()
2018-11-28 11:05:41 +01:00
.Add(() => composition.TypeLoader.GetPackageActions());
2018-11-28 17:35:12 +01:00
composition.WithCollectionBuilder<PropertyValueConverterCollectionBuilder>()
2018-11-28 11:05:41 +01:00
.Append(composition.TypeLoader.GetTypes<IPropertyValueConverter>());
2018-11-29 10:35:16 +01:00
composition.RegisterUnique<IPublishedContentTypeFactory, PublishedContentTypeFactory>();
2017-10-17 17:43:15 +02:00
2018-11-29 10:35:16 +01:00
composition.RegisterUnique<IShortStringHelper>(factory
=> new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetInstance<IUmbracoSettingsSection>())));
2018-11-28 17:35:12 +01:00
composition.WithCollectionBuilder<UrlSegmentProviderCollectionBuilder>()
.Append<DefaultUrlSegmentProvider>();
2018-11-28 17:35:12 +01:00
composition.WithCollectionBuilder<PostMigrationCollectionBuilder>()
2018-11-28 11:05:41 +01:00
.Add(() => composition.TypeLoader.GetTypes<IPostMigration>());
2017-12-22 12:29:56 +01:00
2018-11-29 10:35:16 +01:00
composition.RegisterUnique<IMigrationBuilder>(factory => new MigrationBuilder(factory));
2017-12-26 11:35:21 +01:00
// by default, register a noop factory
2018-11-29 10:35:16 +01:00
composition.RegisterUnique<IPublishedModelFactory, NoopPublishedModelFactory>();
}
2017-07-19 13:42:47 +02:00
internal void Initialize(IEnumerable<Profile> mapperProfiles)
{
2017-07-19 13:42:47 +02:00
// mapper profiles have been registered & are created by the container
Mapper.Initialize(configuration =>
{
2017-07-19 13:42:47 +02:00
foreach (var profile in mapperProfiles)
configuration.AddProfile(profile);
});
2016-09-08 18:43:58 +02:00
// ensure we have some essential directories
// every other component can then initialize safely
IOHelper.EnsurePathExists("~/App_Data");
IOHelper.EnsurePathExists(SystemDirectories.Media);
IOHelper.EnsurePathExists(SystemDirectories.MvcViews);
IOHelper.EnsurePathExists(SystemDirectories.MvcViews + "/Partials");
IOHelper.EnsurePathExists(SystemDirectories.MvcViews + "/MacroPartials");
}
}
}