2018-07-20 09:49:05 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2020-08-21 14:52:47 +01:00
|
|
|
|
using Microsoft.Extensions.Options;
|
2020-09-21 08:19:26 +02:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2018-07-20 09:49:05 +02:00
|
|
|
|
using Umbraco.Core.Cache;
|
2019-11-19 08:52:39 +01:00
|
|
|
|
using Umbraco.Core.Configuration;
|
2020-08-21 14:52:47 +01:00
|
|
|
|
using Umbraco.Core.Configuration.Models;
|
2018-07-20 09:49:05 +02:00
|
|
|
|
using Umbraco.Core.Events;
|
2020-05-25 14:50:51 +02:00
|
|
|
|
using Umbraco.Core.Hosting;
|
2018-07-20 09:49:05 +02:00
|
|
|
|
using Umbraco.Core.IO;
|
2019-01-10 12:44:57 +11:00
|
|
|
|
using Umbraco.Core.Packaging;
|
2020-08-13 10:13:23 +02:00
|
|
|
|
using Umbraco.Core.Routing;
|
2018-07-20 09:49:05 +02:00
|
|
|
|
using Umbraco.Core.Services;
|
|
|
|
|
|
using Umbraco.Core.Services.Implement;
|
|
|
|
|
|
|
2020-01-14 07:47:47 +01:00
|
|
|
|
namespace Umbraco.Core.Composing.CompositionExtensions
|
2018-07-20 09:49:05 +02:00
|
|
|
|
{
|
2019-12-19 12:24:30 +01:00
|
|
|
|
internal static class Services
|
2018-07-20 09:49:05 +02:00
|
|
|
|
{
|
2018-11-27 10:37:33 +01:00
|
|
|
|
public static Composition ComposeServices(this Composition composition)
|
2018-07-20 09:49:05 +02:00
|
|
|
|
{
|
|
|
|
|
|
// register a transient messages factory, which will be replaced by the web
|
|
|
|
|
|
// boot manager when running in a web context
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<IEventMessagesFactory, TransientEventMessagesFactory>();
|
2018-07-20 09:49:05 +02:00
|
|
|
|
|
|
|
|
|
|
// register the service context
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<ServiceContext>();
|
2018-07-20 09:49:05 +02:00
|
|
|
|
|
|
|
|
|
|
// register the special idk map
|
2020-01-22 14:09:20 +01:00
|
|
|
|
composition.RegisterUnique<IIdKeyMap, IdKeyMap>();
|
2018-07-20 09:49:05 +02:00
|
|
|
|
|
|
|
|
|
|
// register the services
|
2019-11-22 13:13:19 +11:00
|
|
|
|
composition.RegisterUnique<IPropertyValidationService, PropertyValidationService>();
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<IKeyValueService, KeyValueService>();
|
|
|
|
|
|
composition.RegisterUnique<IPublicAccessService, PublicAccessService>();
|
|
|
|
|
|
composition.RegisterUnique<IDomainService, DomainService>();
|
|
|
|
|
|
composition.RegisterUnique<IAuditService, AuditService>();
|
|
|
|
|
|
composition.RegisterUnique<ITagService, TagService>();
|
|
|
|
|
|
composition.RegisterUnique<IContentService, ContentService>();
|
|
|
|
|
|
composition.RegisterUnique<IUserService, UserService>();
|
|
|
|
|
|
composition.RegisterUnique<IMemberService, MemberService>();
|
|
|
|
|
|
composition.RegisterUnique<IMediaService, MediaService>();
|
|
|
|
|
|
composition.RegisterUnique<IContentTypeService, ContentTypeService>();
|
2019-02-01 17:16:50 +01:00
|
|
|
|
composition.RegisterUnique<IContentTypeBaseServiceProvider, ContentTypeBaseServiceProvider>();
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<IMediaTypeService, MediaTypeService>();
|
|
|
|
|
|
composition.RegisterUnique<IDataTypeService, DataTypeService>();
|
|
|
|
|
|
composition.RegisterUnique<IFileService, FileService>();
|
|
|
|
|
|
composition.RegisterUnique<ILocalizationService, LocalizationService>();
|
|
|
|
|
|
composition.RegisterUnique<IPackagingService, PackagingService>();
|
|
|
|
|
|
composition.RegisterUnique<IServerRegistrationService, ServerRegistrationService>();
|
|
|
|
|
|
composition.RegisterUnique<IEntityService, EntityService>();
|
|
|
|
|
|
composition.RegisterUnique<IRelationService, RelationService>();
|
|
|
|
|
|
composition.RegisterUnique<IMacroService, MacroService>();
|
|
|
|
|
|
composition.RegisterUnique<IMemberTypeService, MemberTypeService>();
|
|
|
|
|
|
composition.RegisterUnique<IMemberGroupService, MemberGroupService>();
|
|
|
|
|
|
composition.RegisterUnique<INotificationService, NotificationService>();
|
|
|
|
|
|
composition.RegisterUnique<IExternalLoginService, ExternalLoginService>();
|
|
|
|
|
|
composition.RegisterUnique<IRedirectUrlService, RedirectUrlService>();
|
|
|
|
|
|
composition.RegisterUnique<IConsentService, ConsentService>();
|
2018-11-28 11:05:41 +01:00
|
|
|
|
composition.Register<LocalizedTextServiceFileSources>(SourcesFactory);
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<ILocalizedTextService>(factory => new LocalizedTextService(
|
2020-10-27 10:53:01 +00:00
|
|
|
|
factory.GetRequiredService<Lazy<LocalizedTextServiceFileSources>>(),
|
|
|
|
|
|
factory.GetRequiredService<ILogger<LocalizedTextService>>()));
|
2018-07-20 09:49:05 +02:00
|
|
|
|
|
2019-01-10 12:44:57 +11:00
|
|
|
|
composition.RegisterUnique<IEntityXmlSerializer, EntityXmlSerializer>();
|
|
|
|
|
|
|
2019-01-14 17:46:12 +11:00
|
|
|
|
composition.RegisterUnique<IPackageActionRunner, PackageActionRunner>();
|
2019-01-11 14:30:04 +11:00
|
|
|
|
|
2019-01-14 14:28:00 +11:00
|
|
|
|
composition.RegisterUnique<ConflictingPackageData>();
|
|
|
|
|
|
composition.RegisterUnique<CompiledPackageXmlParser>();
|
2019-01-11 14:30:04 +11:00
|
|
|
|
composition.RegisterUnique<ICreatedPackagesRepository>(factory => CreatePackageRepository(factory, "createdPackages.config"));
|
|
|
|
|
|
composition.RegisterUnique<IInstalledPackagesRepository>(factory => CreatePackageRepository(factory, "installedPackages.config"));
|
2019-01-14 17:46:12 +11:00
|
|
|
|
composition.RegisterUnique<PackageDataInstallation>();
|
2019-01-14 14:28:00 +11:00
|
|
|
|
composition.RegisterUnique<PackageFileInstallation>();
|
2020-03-31 17:27:51 +11:00
|
|
|
|
composition.RegisterUnique<IPackageInstallation, PackageInstallation>();
|
2019-01-10 12:44:57 +11:00
|
|
|
|
|
2018-11-27 10:37:33 +01:00
|
|
|
|
return composition;
|
2018-07-20 15:45:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-11 14:30:04 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates an instance of PackagesRepository for either the ICreatedPackagesRepository or the IInstalledPackagesRepository
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="factory"></param>
|
|
|
|
|
|
/// <param name="packageRepoFileName"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private static PackagesRepository CreatePackageRepository(IFactory factory, string packageRepoFileName)
|
2019-01-18 10:02:47 +01:00
|
|
|
|
=> new PackagesRepository(
|
2020-10-27 10:53:01 +00:00
|
|
|
|
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<ILoggerFactory>(),
|
|
|
|
|
|
factory.GetRequiredService<IUmbracoVersion>(),
|
|
|
|
|
|
factory.GetRequiredService<IOptions<GlobalSettings>>(),
|
2019-01-11 14:30:04 +11:00
|
|
|
|
packageRepoFileName);
|
|
|
|
|
|
|
2018-11-28 11:05:41 +01:00
|
|
|
|
private static LocalizedTextServiceFileSources SourcesFactory(IFactory container)
|
2018-07-20 15:45:01 +02:00
|
|
|
|
{
|
2020-10-27 10:53:01 +00:00
|
|
|
|
var hostingEnvironment = container.GetRequiredService<IHostingEnvironment>();
|
|
|
|
|
|
var globalSettings = container.GetRequiredService<IOptions<GlobalSettings>>().Value;
|
2020-09-01 18:10:12 +02:00
|
|
|
|
var mainLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(globalSettings.UmbracoPath , "config","lang")));
|
2020-05-25 14:50:51 +02:00
|
|
|
|
var appPlugins = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins));
|
2020-08-13 10:13:23 +02:00
|
|
|
|
var configLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(Constants.SystemDirectories.Config ,"lang")));
|
2018-07-20 15:45:01 +02:00
|
|
|
|
|
|
|
|
|
|
var pluginLangFolders = appPlugins.Exists == false
|
|
|
|
|
|
? Enumerable.Empty<LocalizedTextServiceSupplementaryFileSource>()
|
|
|
|
|
|
: appPlugins.GetDirectories()
|
2019-08-20 10:58:35 +02:00
|
|
|
|
.SelectMany(x => x.GetDirectories("Lang", SearchOption.AllDirectories))
|
2018-07-20 15:45:01 +02:00
|
|
|
|
.SelectMany(x => x.GetFiles("*.xml", SearchOption.TopDirectoryOnly))
|
|
|
|
|
|
.Select(x => new LocalizedTextServiceSupplementaryFileSource(x, false));
|
|
|
|
|
|
|
|
|
|
|
|
//user defined langs that overwrite the default, these should not be used by plugin creators
|
|
|
|
|
|
var userLangFolders = configLangFolder.Exists == false
|
|
|
|
|
|
? Enumerable.Empty<LocalizedTextServiceSupplementaryFileSource>()
|
|
|
|
|
|
: configLangFolder
|
|
|
|
|
|
.GetFiles("*.user.xml", SearchOption.TopDirectoryOnly)
|
|
|
|
|
|
.Select(x => new LocalizedTextServiceSupplementaryFileSource(x, true));
|
2018-07-20 09:49:05 +02:00
|
|
|
|
|
2018-07-20 15:45:01 +02:00
|
|
|
|
return new LocalizedTextServiceFileSources(
|
2020-10-27 10:53:01 +00:00
|
|
|
|
container.GetRequiredService<ILogger<LocalizedTextServiceFileSources>>(),
|
|
|
|
|
|
container.GetRequiredService<AppCaches>(),
|
2018-07-20 15:45:01 +02:00
|
|
|
|
mainLangFolder,
|
|
|
|
|
|
pluginLangFolders.Concat(userLangFolders));
|
2018-07-20 09:49:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|