2016-09-01 11:25:00 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-11-23 10:33:12 +01:00
|
|
|
|
using System.Configuration;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using LightInject;
|
|
|
|
|
|
using Umbraco.Core.Cache;
|
|
|
|
|
|
using Umbraco.Core.Components;
|
2017-05-30 15:46:25 +02:00
|
|
|
|
using Umbraco.Core.Composing;
|
|
|
|
|
|
using Umbraco.Core.Composing.CompositionRoots;
|
2017-12-28 09:27:57 +01:00
|
|
|
|
using Umbraco.Core.Configuration;
|
|
|
|
|
|
using Umbraco.Core.Configuration.UmbracoSettings;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
|
using Umbraco.Core.Manifest;
|
2017-12-18 18:26:32 +01:00
|
|
|
|
using Umbraco.Core.Migrations;
|
|
|
|
|
|
using Umbraco.Core.Migrations.Install;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
2016-12-16 17:56:10 +01:00
|
|
|
|
using Umbraco.Core.Persistence;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
2017-05-12 14:49:44 +02:00
|
|
|
|
using Umbraco.Core.Scoping;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
using Umbraco.Core.Services;
|
|
|
|
|
|
using Umbraco.Core.Strings;
|
|
|
|
|
|
using Umbraco.Core.Sync;
|
|
|
|
|
|
using Umbraco.Core._Legacy.PackageActions;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
using IntegerValidator = Umbraco.Core.PropertyEditors.IntegerValidator;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2017-12-28 09:27:57 +01:00
|
|
|
|
namespace Umbraco.Core.Runtime
|
2016-09-01 11:25:00 +02:00
|
|
|
|
{
|
|
|
|
|
|
public class CoreRuntimeComponent : UmbracoComponentBase, IRuntimeComponent
|
|
|
|
|
|
{
|
2016-10-07 14:34:55 +02:00
|
|
|
|
public override void Compose(Composition composition)
|
2016-09-01 11:25:00 +02:00
|
|
|
|
{
|
2016-10-07 14:34:55 +02:00
|
|
|
|
base.Compose(composition);
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
|
|
|
|
|
// register from roots
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterFrom<ConfigurationCompositionRoot>();
|
|
|
|
|
|
composition.Container.RegisterFrom<RepositoryCompositionRoot>();
|
|
|
|
|
|
composition.Container.RegisterFrom<ServicesCompositionRoot>();
|
2017-07-19 13:42:47 +02:00
|
|
|
|
composition.Container.RegisterFrom<CoreMappingProfilesCompositionRoot>();
|
2016-09-01 19:06:08 +02:00
|
|
|
|
|
2016-11-29 11:31:38 +01:00
|
|
|
|
// register database builder
|
|
|
|
|
|
// *not* a singleton, don't want to keep it around
|
|
|
|
|
|
composition.Container.Register<DatabaseBuilder>();
|
|
|
|
|
|
|
2016-11-03 10:31:44 +01:00
|
|
|
|
// register filesystems
|
2017-12-14 17:04:44 +01:00
|
|
|
|
composition.Container.RegisterSingleton<FileSystems>();
|
|
|
|
|
|
composition.Container.RegisterSingleton(factory => factory.GetInstance<FileSystems>().MediaFileSystem);
|
|
|
|
|
|
composition.Container.RegisterSingleton(factory => factory.GetInstance<FileSystems>().ScriptsFileSystem, Constants.Composing.FileSystems.ScriptFileSystem);
|
|
|
|
|
|
composition.Container.RegisterSingleton(factory => factory.GetInstance<FileSystems>().PartialViewsFileSystem, Constants.Composing.FileSystems.PartialViewFileSystem);
|
|
|
|
|
|
composition.Container.RegisterSingleton(factory => factory.GetInstance<FileSystems>().MacroPartialsFileSystem, Constants.Composing.FileSystems.PartialViewMacroFileSystem);
|
|
|
|
|
|
composition.Container.RegisterSingleton(factory => factory.GetInstance<FileSystems>().StylesheetsFileSystem, Constants.Composing.FileSystems.StylesheetFileSystem);
|
|
|
|
|
|
composition.Container.RegisterSingleton(factory => factory.GetInstance<FileSystems>().MasterPagesFileSystem, Constants.Composing.FileSystems.MasterpageFileSystem);
|
|
|
|
|
|
composition.Container.RegisterSingleton(factory => factory.GetInstance<FileSystems>().MvcViewsFileSystem, Constants.Composing.FileSystems.ViewFileSystem);
|
|
|
|
|
|
composition.Container.RegisterSingleton(factory => factory.GetInstance<FileSystems>().XsltFileSystem, Constants.Composing.FileSystems.XsltFileSystem);
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
|
|
|
|
|
// register manifest builder, will be injected in eg PropertyEditorCollectionBuilder
|
2018-01-19 19:08:12 +01:00
|
|
|
|
composition.Container.RegisterSingleton<ManifestParser>();
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<PropertyEditorCollectionBuilder>()
|
2017-05-30 15:33:13 +02:00
|
|
|
|
.Add(factory => factory.GetInstance<TypeLoader>().GetPropertyEditors());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<ParameterEditorCollectionBuilder>()
|
2017-05-30 15:33:13 +02:00
|
|
|
|
.Add(factory => factory.GetInstance<TypeLoader>().GetParameterEditors());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
|
|
|
|
|
// register our predefined validators
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<ValidatorCollectionBuilder>()
|
2016-09-01 11:25:00 +02:00
|
|
|
|
.Add<RequiredManifestValueValidator>()
|
|
|
|
|
|
.Add<RegexValidator>()
|
|
|
|
|
|
.Add<DelimitedManifestValueValidator>()
|
|
|
|
|
|
.Add<EmailValidator>()
|
|
|
|
|
|
.Add<IntegerValidator>()
|
|
|
|
|
|
.Add<DecimalValidator>();
|
|
|
|
|
|
|
|
|
|
|
|
// register a server registrar, by default it's the db registrar unless the dev
|
|
|
|
|
|
// has the legacy dist calls enabled - fixme - should obsolete the legacy thing
|
2016-11-23 10:33:12 +01:00
|
|
|
|
composition.Container.RegisterSingleton<IServerRegistrar>(f =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (UmbracoConfig.For.UmbracoSettings().DistributedCall.Enabled)
|
2017-05-30 10:50:09 +02:00
|
|
|
|
return new ConfigServerRegistrar(UmbracoConfig.For.UmbracoSettings(), f.GetInstance<ILogger>());
|
2016-11-23 10:33:12 +01:00
|
|
|
|
if ("true".InvariantEquals(ConfigurationManager.AppSettings["umbracoDisableElectionForSingleServer"]))
|
|
|
|
|
|
return new SingleServerRegistrar(f.GetInstance<IRuntimeState>());
|
|
|
|
|
|
return new DatabaseServerRegistrar(
|
|
|
|
|
|
new Lazy<IServerRegistrationService>(f.GetInstance<IServerRegistrationService>),
|
|
|
|
|
|
new DatabaseServerRegistrarOptions());
|
|
|
|
|
|
});
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
|
|
|
|
|
// by default we'll use the database server messenger with default options (no callbacks),
|
2016-10-07 14:34:55 +02:00
|
|
|
|
// 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
|
|
|
|
|
|
composition.Container.RegisterSingleton<IServerMessenger>(factory
|
2016-09-01 19:06:08 +02:00
|
|
|
|
=> 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>(),
|
2016-09-01 19:06:08 +02:00
|
|
|
|
factory.GetInstance<ILogger>(),
|
|
|
|
|
|
factory.GetInstance<ProfilingLogger>(),
|
|
|
|
|
|
true, new DatabaseServerMessengerOptions()));
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<CacheRefresherCollectionBuilder>()
|
2017-05-30 15:33:13 +02:00
|
|
|
|
.Add(factory => factory.GetInstance<TypeLoader>().GetCacheRefreshers());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<PackageActionCollectionBuilder>()
|
2017-05-30 15:33:13 +02:00
|
|
|
|
.Add(f => f.GetInstance<TypeLoader>().GetPackageActions());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
|
|
|
|
|
// need to filter out the ones we dont want!! fixme - what does that mean?
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<PropertyValueConverterCollectionBuilder>()
|
2017-05-30 15:33:13 +02:00
|
|
|
|
.Append(factory => factory.GetInstance<TypeLoader>().GetTypes<IPropertyValueConverter>());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2017-10-17 17:43:15 +02:00
|
|
|
|
composition.Container.Register<IDataTypeConfigurationSource, DataTypeConfigurationSource>(new PerContainerLifetime());
|
|
|
|
|
|
composition.Container.Register<IPublishedContentTypeFactory, PublishedContentTypeFactory>(new PerContainerLifetime());
|
|
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterSingleton<IShortStringHelper>(factory
|
2016-09-01 11:25:00 +02:00
|
|
|
|
=> new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetInstance<IUmbracoSettingsSection>())));
|
|
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<UrlSegmentProviderCollectionBuilder>()
|
2016-09-01 11:25:00 +02:00
|
|
|
|
.Append<DefaultUrlSegmentProvider>();
|
|
|
|
|
|
|
2017-12-22 12:29:56 +01:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<PostMigrationCollectionBuilder>()
|
|
|
|
|
|
.Add(factory => factory.GetInstance<TypeLoader>().GetTypes<IPostMigration>());
|
|
|
|
|
|
|
2017-12-26 11:35:21 +01:00
|
|
|
|
composition.Container.RegisterSingleton<IMigrationBuilder, MigrationBuilder>();
|
|
|
|
|
|
|
2016-09-01 11:25:00 +02:00
|
|
|
|
// by default, register a noop factory
|
2017-09-26 14:57:50 +02:00
|
|
|
|
composition.Container.RegisterSingleton<IPublishedModelFactory, NoopPublishedModelFactory>();
|
2016-09-01 11:25:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-19 13:42:47 +02:00
|
|
|
|
internal void Initialize(IEnumerable<Profile> mapperProfiles)
|
2016-09-01 11:25:00 +02:00
|
|
|
|
{
|
|
|
|
|
|
//TODO: Remove these for v8!
|
|
|
|
|
|
LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors();
|
|
|
|
|
|
LegacyParameterEditorAliasConverter.CreateMappingsForCoreEditors();
|
|
|
|
|
|
|
2017-07-19 13:42:47 +02:00
|
|
|
|
// mapper profiles have been registered & are created by the container
|
2016-09-01 11:25:00 +02:00
|
|
|
|
Mapper.Initialize(configuration =>
|
|
|
|
|
|
{
|
2017-07-19 13:42:47 +02:00
|
|
|
|
foreach (var profile in mapperProfiles)
|
|
|
|
|
|
configuration.AddProfile(profile);
|
2016-09-01 11:25:00 +02:00
|
|
|
|
});
|
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");
|
2016-09-01 11:25:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|