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 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;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
using Umbraco.Core.IO;
|
2018-06-20 10:49:12 +02:00
|
|
|
|
using Umbraco.Core.IO.MediaPathSchemes;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
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;
|
2018-11-27 10:37:33 +01:00
|
|
|
|
using Umbraco.Core.Persistence.Mappers;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
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;
|
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;
|
2018-01-20 12:09:15 +01:00
|
|
|
|
using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.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
|
|
|
|
|
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-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
|
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>();
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
|
|
|
|
|
// 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>()
|
2016-09-01 11:25:00 +02:00
|
|
|
|
.Add<RegexValidator>()
|
2018-03-16 09:06:44 +01:00
|
|
|
|
.Add<DelimitedValueValidator>()
|
2016-09-01 11:25:00 +02:00
|
|
|
|
.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 =>
|
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
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<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>(),
|
2018-11-27 10:37:33 +01:00
|
|
|
|
factory.GetInstance<IProfilingLogger>(),
|
2018-04-06 13:51:54 +10:00
|
|
|
|
factory.GetInstance<IGlobalSettings>(),
|
2016-09-01 19:06:08 +02:00
|
|
|
|
true, new DatabaseServerMessengerOptions()));
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2018-11-28 17:35:12 +01:00
|
|
|
|
composition.WithCollectionBuilder<CacheRefresherCollectionBuilder>()
|
2018-11-28 11:05:41 +01:00
|
|
|
|
.Add(() => composition.TypeLoader.GetCacheRefreshers());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2018-11-28 17:35:12 +01:00
|
|
|
|
composition.WithCollectionBuilder<PackageActionCollectionBuilder>()
|
2018-11-28 11:05:41 +01:00
|
|
|
|
.Add(() => composition.TypeLoader.GetPackageActions());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2018-11-28 17:35:12 +01:00
|
|
|
|
composition.WithCollectionBuilder<PropertyValueConverterCollectionBuilder>()
|
2018-11-28 11:05:41 +01:00
|
|
|
|
.Append(composition.TypeLoader.GetTypes<IPropertyValueConverter>());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
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
|
2016-09-01 11:25:00 +02:00
|
|
|
|
=> new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetInstance<IUmbracoSettingsSection>())));
|
|
|
|
|
|
|
2018-11-28 17:35:12 +01:00
|
|
|
|
composition.WithCollectionBuilder<UrlSegmentProviderCollectionBuilder>()
|
2016-09-01 11:25:00 +02:00
|
|
|
|
.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
|
|
|
|
|
2016-09-01 11:25:00 +02:00
|
|
|
|
// by default, register a noop factory
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<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
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|