2020-12-24 11:46:17 +11:00
|
|
|
using System.Runtime.InteropServices;
|
2020-04-01 15:50:46 +02:00
|
|
|
using Examine;
|
2020-10-27 10:53:01 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-12-24 11:46:17 +11:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-10-05 21:45:51 +02:00
|
|
|
using Microsoft.Extensions.Options;
|
2020-12-15 21:47:15 +00:00
|
|
|
using Umbraco.Core;
|
2019-01-03 21:00:28 +01:00
|
|
|
using Umbraco.Core.Configuration;
|
2020-10-05 21:45:51 +02:00
|
|
|
using Umbraco.Core.Configuration.Models;
|
2020-02-18 11:32:31 +01:00
|
|
|
using Umbraco.Core.Dashboards;
|
2020-12-04 15:04:29 +01:00
|
|
|
using Umbraco.Core.DependencyInjection;
|
2020-12-24 11:46:17 +11:00
|
|
|
using Umbraco.Core.Hosting;
|
2020-04-20 12:20:47 +02:00
|
|
|
using Umbraco.Core.Install;
|
2020-12-24 11:46:17 +11:00
|
|
|
using Umbraco.Core.Mail;
|
2019-01-03 21:00:28 +01:00
|
|
|
using Umbraco.Core.Manifest;
|
2020-04-01 15:50:46 +02:00
|
|
|
using Umbraco.Core.Media;
|
2019-01-03 21:00:28 +01:00
|
|
|
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;
|
2020-12-16 22:26:47 +01:00
|
|
|
using Umbraco.Core.Packaging;
|
2020-12-24 11:46:17 +11:00
|
|
|
using Umbraco.Core.Persistence;
|
2019-01-03 21:00:28 +01:00
|
|
|
using Umbraco.Core.PropertyEditors;
|
|
|
|
|
using Umbraco.Core.PropertyEditors.Validators;
|
2020-04-01 15:50:46 +02:00
|
|
|
using Umbraco.Core.PropertyEditors.ValueConverters;
|
2020-12-24 11:46:17 +11:00
|
|
|
using Umbraco.Core.Runtime;
|
2019-01-03 21:00:28 +01:00
|
|
|
using Umbraco.Core.Scoping;
|
2019-11-07 21:28:56 +11:00
|
|
|
using Umbraco.Core.Serialization;
|
2019-01-03 21:00:28 +01:00
|
|
|
using Umbraco.Core.Strings;
|
2020-10-05 21:45:51 +02:00
|
|
|
using Umbraco.Core.Templates;
|
2020-12-24 14:29:26 +11:00
|
|
|
using Umbraco.Core.Trees;
|
2020-04-01 15:50:46 +02:00
|
|
|
using Umbraco.Examine;
|
2020-08-19 19:42:58 +02:00
|
|
|
using Umbraco.Infrastructure.Examine;
|
2020-04-01 15:50:46 +02:00
|
|
|
using Umbraco.Infrastructure.Media;
|
2020-12-24 09:50:05 +11:00
|
|
|
using Umbraco.Infrastructure.Runtime;
|
2020-02-17 12:07:51 +01:00
|
|
|
using Umbraco.Web;
|
2020-04-01 15:50:46 +02:00
|
|
|
using Umbraco.Web.Actions;
|
|
|
|
|
using Umbraco.Web.ContentApps;
|
|
|
|
|
using Umbraco.Web.Editors;
|
|
|
|
|
using Umbraco.Web.HealthCheck;
|
|
|
|
|
using Umbraco.Web.HealthCheck.NotificationMethods;
|
2020-02-17 14:58:34 +01:00
|
|
|
using Umbraco.Web.Install;
|
2020-10-05 21:45:51 +02:00
|
|
|
using Umbraco.Web.Media;
|
2020-04-01 15:50:46 +02:00
|
|
|
using Umbraco.Web.Media.EmbedProviders;
|
2020-03-28 15:04:36 +01:00
|
|
|
using Umbraco.Web.Migrations.PostMigrations;
|
|
|
|
|
using Umbraco.Web.Models.PublishedContent;
|
2020-02-18 13:56:31 +01:00
|
|
|
using Umbraco.Web.PropertyEditors;
|
2020-08-06 12:59:21 +02:00
|
|
|
using Umbraco.Web.PropertyEditors.ValueConverters;
|
2020-03-28 15:04:36 +01:00
|
|
|
using Umbraco.Web.PublishedCache;
|
2020-04-01 15:50:46 +02:00
|
|
|
using Umbraco.Web.Routing;
|
|
|
|
|
using Umbraco.Web.Search;
|
|
|
|
|
using Umbraco.Web.Sections;
|
2020-03-28 15:04:36 +01:00
|
|
|
using Umbraco.Web.Trees;
|
2019-01-03 21:00:28 +01:00
|
|
|
|
2020-12-24 09:50:05 +11:00
|
|
|
namespace Umbraco.Infrastructure.DependencyInjection
|
2019-01-03 21:00:28 +01:00
|
|
|
{
|
2020-12-24 09:50:05 +11:00
|
|
|
public static partial class UmbracoBuilderExtensions
|
2019-01-03 21:00:28 +01:00
|
|
|
{
|
2020-12-24 09:50:05 +11:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* TODO: Many of these things are not "Core" services and are probably not required to run
|
2020-12-24 11:46:17 +11:00
|
|
|
*
|
2020-12-24 09:50:05 +11:00
|
|
|
* This should be split up:
|
|
|
|
|
* - Distributed Cache
|
|
|
|
|
* - BackOffice
|
|
|
|
|
* - Manifest
|
|
|
|
|
* - Property Editors
|
|
|
|
|
* - Packages
|
|
|
|
|
* - Dashboards
|
|
|
|
|
* - OEmbed
|
|
|
|
|
* - Sections
|
|
|
|
|
* - Content Apps
|
|
|
|
|
* - Health Checks
|
|
|
|
|
* - ETC...
|
|
|
|
|
* - Installation
|
|
|
|
|
* - Front End
|
|
|
|
|
*/
|
|
|
|
|
|
2020-12-24 11:46:17 +11:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds all core Umbraco services required to run which may be replaced later in the pipeline
|
|
|
|
|
/// </summary>
|
2020-12-15 21:47:15 +00:00
|
|
|
public static IUmbracoBuilder AddCoreInitialServices(this IUmbracoBuilder builder)
|
2019-01-03 21:00:28 +01:00
|
|
|
{
|
2020-12-24 11:46:17 +11:00
|
|
|
builder.AddMainDom();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
2020-12-24 11:46:17 +11:00
|
|
|
builder.Services.AddUnique<IUmbracoDatabaseFactory, UmbracoDatabaseFactory>();
|
|
|
|
|
builder.Services.AddUnique(factory => factory.GetRequiredService<IUmbracoDatabaseFactory>().CreateDatabase());
|
|
|
|
|
builder.Services.AddUnique(factory => factory.GetRequiredService<IUmbracoDatabaseFactory>().SqlContext);
|
|
|
|
|
builder.Services.AddUnique<IRuntimeState, RuntimeState>();
|
|
|
|
|
builder.Services.AddUnique<IRuntime, CoreRuntime>();
|
2020-12-15 21:47:15 +00:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
// composers
|
2020-11-18 17:40:23 +00:00
|
|
|
builder
|
2020-12-24 11:46:17 +11:00
|
|
|
.AddRepositories()
|
|
|
|
|
.AddServices()
|
|
|
|
|
.AddCoreMappingProfiles()
|
|
|
|
|
.AddFileSystems();
|
2019-01-03 21:00:28 +01:00
|
|
|
|
|
|
|
|
// 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
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Mappers().AddCoreMappers();
|
2019-01-03 21:00:28 +01:00
|
|
|
|
|
|
|
|
// register the scope provider
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<ScopeProvider>(); // implements both IScopeProvider and IScopeAccessor
|
|
|
|
|
builder.Services.AddUnique<IScopeProvider>(f => f.GetRequiredService<ScopeProvider>());
|
|
|
|
|
builder.Services.AddUnique<IScopeAccessor>(f => f.GetRequiredService<ScopeProvider>());
|
2019-01-03 21:00:28 +01:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IJsonSerializer, JsonNetSerializer>();
|
|
|
|
|
builder.Services.AddUnique<IConfigurationEditorJsonSerializer, ConfigurationEditorJsonSerializer>();
|
|
|
|
|
builder.Services.AddUnique<IMenuItemCollectionFactory, MenuItemCollectionFactory>();
|
2019-11-07 21:28:56 +11:00
|
|
|
|
2019-01-03 21:00:28 +01:00
|
|
|
// register database builder
|
|
|
|
|
// *not* a singleton, don't want to keep it around
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddTransient<DatabaseBuilder>();
|
2019-01-03 21:00:28 +01:00
|
|
|
|
|
|
|
|
// register manifest parser, will be injected in collection builders where needed
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IManifestParser, ManifestParser>();
|
2019-01-03 21:00:28 +01:00
|
|
|
|
2019-06-27 12:42:14 +02:00
|
|
|
// register the manifest filter collection builder (collection is empty by default)
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.ManifestFilters();
|
2019-06-27 12:42:14 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.MediaUrlGenerators()
|
2020-02-18 13:56:31 +01:00
|
|
|
.Add<FileUploadPropertyEditor>()
|
|
|
|
|
.Add<ImageCropperPropertyEditor>();
|
|
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IPublishedContentTypeFactory, PublishedContentTypeFactory>();
|
2019-01-03 21:00:28 +01:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IShortStringHelper>(factory
|
2020-10-27 10:53:01 +00:00
|
|
|
=> new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetRequiredService<IOptions<RequestHandlerSettings>>().Value)));
|
2019-01-03 21:00:28 +01:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IMigrationBuilder>(factory => new MigrationBuilder(factory));
|
2019-01-03 21:00:28 +01:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IPublishedSnapshotRebuilder, PublishedSnapshotRebuilder>();
|
2019-11-25 21:20:00 +11:00
|
|
|
|
2020-02-13 11:21:20 +01:00
|
|
|
// register the published snapshot accessor - the "current" published snapshot is in the umbraco context
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IPublishedSnapshotAccessor, UmbracoContextPublishedSnapshotAccessor>();
|
2020-02-13 11:40:56 +01:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IVariationContextAccessor, HybridVariationContextAccessor>();
|
2020-02-18 11:38:51 +01:00
|
|
|
|
2020-03-24 11:53:56 +11:00
|
|
|
// Config manipulator
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IConfigManipulator, JsonConfigManipulator>();
|
2020-11-03 11:20:51 +01:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<RichTextEditorPastedImages>();
|
|
|
|
|
builder.Services.AddUnique<BlockEditorConverter>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
|
|
|
|
// both TinyMceValueConverter (in Core) and RteMacroRenderingValueConverter (in Web) will be
|
2020-12-24 14:29:26 +11:00
|
|
|
// discovered when CoreBootManager configures the converters. We will remove the basic one defined
|
|
|
|
|
// in core so that the more enhanced version is active.
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.PropertyValueConverters()
|
2020-12-24 14:29:26 +11:00
|
|
|
.Remove<SimpleTinyMceValueConverter>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IImageUrlGenerator, ImageSharpImageUrlGenerator>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IPublishedSnapshotRebuilder, PublishedSnapshotRebuilder>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
|
|
|
|
// register *all* checks, except those marked [HideFromTypeFinder] of course
|
2020-12-04 13:01:58 +01:00
|
|
|
builder.Services.AddUnique<IMarkdownToHtmlConverter, MarkdownToHtmlConverter>();
|
2020-12-24 14:29:26 +11:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IContentLastChanceFinder, ContentFinderByConfigured404>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddScoped<UmbracoTreeSearcher>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
2020-12-24 11:46:17 +11:00
|
|
|
// replace
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IEmailSender, EmailSender>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IExamineManager, ExamineManager>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddScoped<ITagQuery, TagQuery>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IUmbracoTreeSearcherFields, UmbracoTreeSearcherFields>();
|
|
|
|
|
builder.Services.AddScoped<IPublishedContentQuery>(factory =>
|
2020-04-01 15:50:46 +02:00
|
|
|
{
|
2020-10-27 10:53:01 +00:00
|
|
|
var umbCtx = factory.GetRequiredService<IUmbracoContextAccessor>();
|
|
|
|
|
return new PublishedContentQuery(umbCtx.UmbracoContext.PublishedSnapshot, factory.GetRequiredService<IVariationContextAccessor>(), factory.GetRequiredService<IExamineManager>());
|
2020-10-30 11:16:17 +00:00
|
|
|
});
|
2020-04-01 15:50:46 +02:00
|
|
|
|
|
|
|
|
// register accessors for cultures
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IDefaultCultureAccessor, DefaultCultureAccessor>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddSingleton<IFilePermissionHelper, FilePermissionHelper>();
|
2020-04-01 15:50:46 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IUmbracoComponentRenderer, UmbracoComponentRenderer>();
|
2020-06-04 12:53:08 +02:00
|
|
|
|
2020-08-19 19:42:58 +02:00
|
|
|
// Register noop versions for examine to be overridden by examine
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<IUmbracoIndexesCreator, NoopUmbracoIndexesCreator>();
|
|
|
|
|
builder.Services.AddUnique<IBackOfficeExamineSearcher, NoopBackOfficeExamineSearcher>();
|
2020-09-22 21:19:41 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<UploadAutoFillProperties>();
|
2020-09-22 21:19:41 +02:00
|
|
|
|
2020-11-18 17:40:23 +00:00
|
|
|
builder.Services.AddUnique<ICronTabParser, NCronTabParser>();
|
2020-11-19 23:53:04 +11:00
|
|
|
|
2020-12-04 15:04:29 +01:00
|
|
|
builder.Services.AddUnique<IImageDimensionExtractor, ImageDimensionExtractor>();
|
2020-12-16 22:26:47 +01:00
|
|
|
|
|
|
|
|
builder.Services.AddUnique<PackageDataInstallation>();
|
2020-12-15 21:47:15 +00:00
|
|
|
|
2020-12-24 14:29:26 +11:00
|
|
|
builder.AddInstaller();
|
|
|
|
|
|
2020-12-15 21:47:15 +00:00
|
|
|
return builder;
|
2019-01-03 21:00:28 +01:00
|
|
|
}
|
2020-12-24 11:46:17 +11:00
|
|
|
|
|
|
|
|
private static IUmbracoBuilder AddMainDom(this IUmbracoBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.Services.AddUnique<IMainDom, MainDom>();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddUnique<IMainDomLock>(factory =>
|
|
|
|
|
{
|
|
|
|
|
var globalSettings = factory.GetRequiredService<IOptions<GlobalSettings>>().Value;
|
|
|
|
|
var connectionStrings = factory.GetRequiredService<IOptions<ConnectionStrings>>().Value;
|
|
|
|
|
var hostingEnvironment = factory.GetRequiredService<IHostingEnvironment>();
|
|
|
|
|
|
|
|
|
|
var dbCreator = factory.GetRequiredService<IDbProviderFactoryCreator>();
|
|
|
|
|
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
|
|
|
|
var loggerFactory = factory.GetRequiredService<ILoggerFactory>();
|
|
|
|
|
|
|
|
|
|
return globalSettings.MainDomLock.Equals("SqlMainDomLock") || isWindows == false
|
|
|
|
|
? (IMainDomLock)new SqlMainDomLock(loggerFactory.CreateLogger<SqlMainDomLock>(), loggerFactory, globalSettings, connectionStrings, dbCreator, hostingEnvironment)
|
|
|
|
|
: new MainDomSemaphoreLock(loggerFactory.CreateLogger<MainDomSemaphoreLock>(), hostingEnvironment);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
2019-01-03 21:00:28 +01:00
|
|
|
}
|
|
|
|
|
}
|