2020-10-30 11:16:17 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2022-05-02 19:38:33 +02:00
|
|
|
using Microsoft.Extensions.FileProviders;
|
2020-09-21 08:19:26 +02:00
|
|
|
using Microsoft.Extensions.Logging;
|
2020-12-16 22:26:47 +01:00
|
|
|
using Microsoft.Extensions.Options;
|
2021-02-23 12:24:51 +01:00
|
|
|
using Umbraco.Cms.Core;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Cache;
|
2022-05-02 19:38:33 +02:00
|
|
|
using Umbraco.Cms.Core.Composing;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
|
|
|
using Umbraco.Cms.Core.DependencyInjection;
|
2022-06-02 08:18:31 +02:00
|
|
|
using Umbraco.Cms.Core.Hosting;
|
2021-07-06 15:09:56 -06:00
|
|
|
using Umbraco.Cms.Core.IO;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Packaging;
|
2022-05-02 15:42:19 +02:00
|
|
|
using Umbraco.Cms.Core.PropertyEditors;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Routing;
|
2022-05-02 15:42:19 +02:00
|
|
|
using Umbraco.Cms.Core.Serialization;
|
2021-02-09 10:22:42 +01:00
|
|
|
using Umbraco.Cms.Core.Services;
|
2021-02-23 12:24:51 +01:00
|
|
|
using Umbraco.Cms.Core.Services.Implement;
|
2022-05-02 15:42:19 +02:00
|
|
|
using Umbraco.Cms.Core.Strings;
|
2021-06-15 15:05:57 +10:00
|
|
|
using Umbraco.Cms.Infrastructure.Packaging;
|
2021-12-21 14:02:49 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement;
|
2022-05-02 15:42:19 +02:00
|
|
|
using Umbraco.Cms.Infrastructure.Scoping;
|
2022-04-29 11:52:58 +02:00
|
|
|
using Umbraco.Cms.Infrastructure.Services;
|
2022-04-20 15:42:27 +02:00
|
|
|
using Umbraco.Cms.Infrastructure.Services.Implement;
|
|
|
|
|
using Umbraco.Cms.Infrastructure.Telemetry.Providers;
|
2022-03-10 16:25:47 +01:00
|
|
|
using Umbraco.Cms.Infrastructure.Templates;
|
2022-10-19 14:13:56 +02:00
|
|
|
using Umbraco.Cms.Infrastructure.Templates.PartialViews;
|
2021-02-09 13:32:34 +01:00
|
|
|
using Umbraco.Extensions;
|
2022-04-29 11:52:58 +02:00
|
|
|
using CacheInstructionService = Umbraco.Cms.Core.Services.Implement.CacheInstructionService;
|
2018-07-20 09:49:05 +02:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
namespace Umbraco.Cms.Infrastructure.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
public static partial class UmbracoBuilderExtensions
|
2018-07-20 09:49:05 +02:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds Umbraco services
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static IUmbracoBuilder AddServices(this IUmbracoBuilder builder)
|
2018-07-20 09:49:05 +02:00
|
|
|
{
|
2022-06-02 08:18:31 +02:00
|
|
|
// register the service context
|
|
|
|
|
builder.Services.AddSingleton<ServiceContext>();
|
2018-07-20 09:49:05 +02:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
// register the special idk map
|
|
|
|
|
builder.Services.AddUnique<IIdKeyMap, IdKeyMap>();
|
2023-03-29 08:14:47 +02:00
|
|
|
builder.Services.AddUnique<IUserIdKeyResolver, UserIdKeyResolver>();
|
2022-04-29 11:52:58 +02:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
builder.Services.AddUnique<IAuditService, AuditService>();
|
|
|
|
|
builder.Services.AddUnique<ICacheInstructionService, CacheInstructionService>();
|
|
|
|
|
builder.Services.AddUnique<IBasicAuthService, BasicAuthService>();
|
|
|
|
|
builder.Services.AddUnique<IDataTypeService, DataTypeService>();
|
|
|
|
|
builder.Services.AddUnique<IPackagingService, PackagingService>();
|
|
|
|
|
builder.Services.AddUnique<IServerRegistrationService, ServerRegistrationService>();
|
|
|
|
|
builder.Services.AddUnique<ITwoFactorLoginService, TwoFactorLoginService>();
|
|
|
|
|
builder.Services.AddTransient(CreateLocalizedTextServiceFileSourcesFactory);
|
|
|
|
|
builder.Services.AddUnique(factory => CreatePackageRepository(factory, "createdPackages.config"));
|
|
|
|
|
builder.Services.AddUnique<ICreatedPackagesRepository, CreatedPackageSchemaRepository>();
|
|
|
|
|
builder.Services.AddSingleton(CreatePackageDataInstallation);
|
|
|
|
|
builder.Services.AddUnique<IPackageInstallation, PackageInstallation>();
|
|
|
|
|
builder.Services.AddUnique<IHtmlMacroParameterParser, HtmlMacroParameterParser>();
|
|
|
|
|
builder.Services.AddTransient<IExamineIndexCountService, ExamineIndexCountService>();
|
|
|
|
|
builder.Services.AddUnique<IUserDataService, SystemInformationTelemetryProvider>();
|
|
|
|
|
builder.Services.AddTransient<IUsageInformationService, UsageInformationService>();
|
2022-08-31 11:03:34 +02:00
|
|
|
builder.Services.AddSingleton<IEditorConfigurationParser, EditorConfigurationParser>();
|
2022-10-19 14:13:56 +02:00
|
|
|
builder.Services.AddTransient<IPartialViewPopulator, PartialViewPopulator>();
|
2018-07-20 15:45:01 +02:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
return builder;
|
|
|
|
|
}
|
2022-05-02 15:42:19 +02:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
private static PackagesRepository CreatePackageRepository(IServiceProvider factory, string packageRepoFileName)
|
|
|
|
|
=> new(
|
|
|
|
|
factory.GetRequiredService<IContentService>(),
|
|
|
|
|
factory.GetRequiredService<IContentTypeService>(),
|
|
|
|
|
factory.GetRequiredService<IDataTypeService>(),
|
|
|
|
|
factory.GetRequiredService<IFileService>(),
|
|
|
|
|
factory.GetRequiredService<IMacroService>(),
|
|
|
|
|
factory.GetRequiredService<ILocalizationService>(),
|
|
|
|
|
factory.GetRequiredService<IHostingEnvironment>(),
|
|
|
|
|
factory.GetRequiredService<IEntityXmlSerializer>(),
|
|
|
|
|
factory.GetRequiredService<IOptions<GlobalSettings>>(),
|
|
|
|
|
factory.GetRequiredService<IMediaService>(),
|
|
|
|
|
factory.GetRequiredService<IMediaTypeService>(),
|
|
|
|
|
factory.GetRequiredService<MediaFileManager>(),
|
|
|
|
|
factory.GetRequiredService<FileSystems>(),
|
|
|
|
|
packageRepoFileName);
|
2019-01-11 14:30:04 +11:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
// Factory registration is only required because of ambiguous constructor
|
|
|
|
|
private static PackageDataInstallation CreatePackageDataInstallation(IServiceProvider factory)
|
|
|
|
|
=> new(
|
|
|
|
|
factory.GetRequiredService<IDataValueEditorFactory>(),
|
|
|
|
|
factory.GetRequiredService<ILogger<PackageDataInstallation>>(),
|
|
|
|
|
factory.GetRequiredService<IFileService>(),
|
|
|
|
|
factory.GetRequiredService<IMacroService>(),
|
|
|
|
|
factory.GetRequiredService<ILocalizationService>(),
|
|
|
|
|
factory.GetRequiredService<IDataTypeService>(),
|
|
|
|
|
factory.GetRequiredService<IEntityService>(),
|
|
|
|
|
factory.GetRequiredService<IContentTypeService>(),
|
|
|
|
|
factory.GetRequiredService<IContentService>(),
|
|
|
|
|
factory.GetRequiredService<PropertyEditorCollection>(),
|
|
|
|
|
factory.GetRequiredService<IScopeProvider>(),
|
|
|
|
|
factory.GetRequiredService<IShortStringHelper>(),
|
|
|
|
|
factory.GetRequiredService<IConfigurationEditorJsonSerializer>(),
|
|
|
|
|
factory.GetRequiredService<IMediaService>(),
|
|
|
|
|
factory.GetRequiredService<IMediaTypeService>());
|
2018-07-20 09:49:05 +02:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
private static LocalizedTextServiceFileSources CreateLocalizedTextServiceFileSourcesFactory(
|
|
|
|
|
IServiceProvider container)
|
|
|
|
|
{
|
|
|
|
|
IHostingEnvironment hostingEnvironment = container.GetRequiredService<IHostingEnvironment>();
|
2022-10-18 08:22:27 +02:00
|
|
|
|
|
|
|
|
// TODO: (for >= v13) Rethink whether all language files (.xml and .user.xml) should be located in ~/config/lang
|
|
|
|
|
// instead of ~/umbraco/config/lang and ~/config/lang.
|
|
|
|
|
// Currently when extending Umbraco, a new language file that the backoffice will be available in, should be placed
|
|
|
|
|
// in ~/umbraco/config/lang, while 'user' translation files for overrides are in ~/config/lang (according to our docs).
|
|
|
|
|
// Such change will be breaking and we would need to document this clearly.
|
2022-06-02 08:18:31 +02:00
|
|
|
var subPath = WebPath.Combine(Constants.SystemDirectories.Umbraco, "config", "lang");
|
2022-10-18 08:22:27 +02:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
var mainLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(subPath));
|
2022-05-02 19:38:33 +02:00
|
|
|
|
2022-06-02 08:18:31 +02:00
|
|
|
return new LocalizedTextServiceFileSources(
|
|
|
|
|
container.GetRequiredService<ILogger<LocalizedTextServiceFileSources>>(),
|
|
|
|
|
container.GetRequiredService<AppCaches>(),
|
|
|
|
|
mainLangFolder,
|
|
|
|
|
container.GetServices<LocalizedTextServiceSupplementaryFileSource>(),
|
|
|
|
|
new EmbeddedFileProvider(typeof(IAssemblyProvider).Assembly, "Umbraco.Cms.Core.EmbeddedResources.Lang")
|
|
|
|
|
.GetDirectoryContents(string.Empty));
|
2018-07-20 09:49:05 +02:00
|
|
|
}
|
|
|
|
|
}
|