2016-09-01 11:25:00 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using LightInject;
|
|
|
|
|
|
using Umbraco.Core.Cache;
|
|
|
|
|
|
using Umbraco.Core.Components;
|
|
|
|
|
|
using Umbraco.Core.Configuration;
|
|
|
|
|
|
using Umbraco.Core.Configuration.UmbracoSettings;
|
2016-10-07 14:34:55 +02:00
|
|
|
|
using Umbraco.Core.DI;
|
2016-09-01 11:25:00 +02:00
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
|
using Umbraco.Core.Manifest;
|
|
|
|
|
|
using Umbraco.Core.Models.Mapping;
|
|
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
|
|
|
|
|
using Umbraco.Core.Persistence.Migrations;
|
|
|
|
|
|
using Umbraco.Core.Plugins;
|
|
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core
|
|
|
|
|
|
{
|
|
|
|
|
|
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>();
|
|
|
|
|
|
composition.Container.RegisterFrom<CoreModelMappersCompositionRoot>();
|
2016-09-01 19:06:08 +02:00
|
|
|
|
|
2016-09-01 11:25:00 +02:00
|
|
|
|
//TODO: Don't think we'll need this when the resolvers are all container resolvers
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterSingleton<IServiceProvider, ActivatorServiceProvider>();
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2016-11-03 10:31:44 +01:00
|
|
|
|
// register filesystems
|
|
|
|
|
|
composition.Container.Register<FileSystems>();
|
|
|
|
|
|
composition.Container.Register(factory => factory.GetInstance<FileSystems>().MediaFileSystem);
|
|
|
|
|
|
composition.Container.RegisterSingleton<IFileSystem>(factory => factory.GetInstance<FileSystems>().ScriptsFileSystem, "ScriptFileSystem");
|
|
|
|
|
|
composition.Container.RegisterSingleton<IFileSystem>(factory => factory.GetInstance<FileSystems>().PartialViewsFileSystem, "PartialViewFileSystem");
|
|
|
|
|
|
composition.Container.RegisterSingleton<IFileSystem>(factory => factory.GetInstance<FileSystems>().MacroPartialsFileSystem, "PartialViewMacroFileSystem");
|
|
|
|
|
|
composition.Container.RegisterSingleton<IFileSystem>(factory => factory.GetInstance<FileSystems>().StylesheetsFileSystem, "StylesheetFileSystem");
|
|
|
|
|
|
composition.Container.RegisterSingleton<IFileSystem>(factory => factory.GetInstance<FileSystems>().MasterPagesFileSystem, "MasterpageFileSystem");
|
|
|
|
|
|
composition.Container.RegisterSingleton<IFileSystem>(factory => factory.GetInstance<FileSystems>().MvcViewsFileSystem, "ViewFileSystem");
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
|
|
|
|
|
// register manifest builder, will be injected in eg PropertyEditorCollectionBuilder
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterSingleton(factory
|
2016-09-01 11:25:00 +02:00
|
|
|
|
=> new ManifestParser(factory.GetInstance<ILogger>(), new DirectoryInfo(IOHelper.MapPath("~/App_Plugins")), factory.GetInstance<IRuntimeCacheProvider>()));
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterSingleton<ManifestBuilder>();
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<PropertyEditorCollectionBuilder>()
|
2016-09-23 20:18:25 +02:00
|
|
|
|
.Add(factory => factory.GetInstance<PluginManager>().ResolvePropertyEditors());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<ParameterEditorCollectionBuilder>()
|
2016-09-23 20:18:25 +02:00
|
|
|
|
.Add(factory => factory.GetInstance<PluginManager>().ResolveParameterEditors());
|
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-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterSingleton(factory => UmbracoConfig.For.UmbracoSettings().DistributedCall.Enabled
|
2016-09-01 11:25:00 +02:00
|
|
|
|
? (IServerRegistrar)new ConfigServerRegistrar(UmbracoConfig.For.UmbracoSettings())
|
|
|
|
|
|
: (IServerRegistrar)new DatabaseServerRegistrar(
|
2016-09-01 19:06:08 +02:00
|
|
|
|
new Lazy<IServerRegistrationService>(factory.GetInstance<IServerRegistrationService>),
|
2016-09-01 11:25:00 +02:00
|
|
|
|
new DatabaseServerRegistrarOptions()));
|
|
|
|
|
|
|
|
|
|
|
|
// 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>(),
|
|
|
|
|
|
factory.GetInstance<DatabaseContext>(),
|
|
|
|
|
|
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>()
|
2016-09-23 20:18:25 +02:00
|
|
|
|
.Add(factory => factory.GetInstance<PluginManager>().ResolveCacheRefreshers());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<PackageActionCollectionBuilder>()
|
2016-09-23 20:18:25 +02:00
|
|
|
|
.Add(f => f.GetInstance<PluginManager>().ResolvePackageActions());
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterCollectionBuilder<MigrationCollectionBuilder>()
|
2016-09-23 20:18:25 +02:00
|
|
|
|
.Add(factory => factory.GetInstance<PluginManager>().ResolveTypes<IMigration>());
|
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>()
|
2016-09-01 11:25:00 +02:00
|
|
|
|
.Append(factory => factory.GetInstance<PluginManager>().ResolveTypes<IPropertyValueConverter>());
|
|
|
|
|
|
|
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>();
|
|
|
|
|
|
|
|
|
|
|
|
// by default, register a noop factory
|
2016-10-07 14:34:55 +02:00
|
|
|
|
composition.Container.RegisterSingleton<IPublishedContentModelFactory, NoopPublishedContentModelFactory>();
|
2016-09-01 11:25:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-01 19:06:08 +02:00
|
|
|
|
internal void Initialize(
|
|
|
|
|
|
IEnumerable<ModelMapperConfiguration> modelMapperConfigurations)
|
2016-09-01 11:25:00 +02:00
|
|
|
|
{
|
|
|
|
|
|
//TODO: Remove these for v8!
|
|
|
|
|
|
LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors();
|
|
|
|
|
|
LegacyParameterEditorAliasConverter.CreateMappingsForCoreEditors();
|
|
|
|
|
|
|
2016-09-01 19:06:08 +02:00
|
|
|
|
// model mapper configurations have been registered & are created by the container
|
2016-09-01 11:25:00 +02:00
|
|
|
|
Mapper.Initialize(configuration =>
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var m in modelMapperConfigurations)
|
2016-09-01 19:06:08 +02:00
|
|
|
|
m.ConfigureMappings(configuration);
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|