2018-07-20 09:49:05 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Umbraco.Core.Cache;
|
2018-11-27 10:37:33 +01:00
|
|
|
|
using Umbraco.Core.Components;
|
2018-07-20 09:49:05 +02:00
|
|
|
|
using Umbraco.Core.Events;
|
|
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
2019-01-10 12:44:57 +11:00
|
|
|
|
using Umbraco.Core.Packaging;
|
2018-07-20 09:49:05 +02:00
|
|
|
|
using Umbraco.Core.Services;
|
|
|
|
|
|
using Umbraco.Core.Services.Implement;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Composing.Composers
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class ServicesComposer
|
|
|
|
|
|
{
|
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
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<IdkMap>();
|
2018-07-20 09:49:05 +02:00
|
|
|
|
|
|
|
|
|
|
// register the services
|
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>();
|
|
|
|
|
|
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(
|
2018-07-20 09:49:05 +02:00
|
|
|
|
factory.GetInstance<Lazy<LocalizedTextServiceFileSources>>(),
|
|
|
|
|
|
factory.GetInstance<ILogger>()));
|
|
|
|
|
|
|
2019-01-10 12:44:57 +11:00
|
|
|
|
composition.RegisterUnique<IEntityXmlSerializer, EntityXmlSerializer>();
|
|
|
|
|
|
|
|
|
|
|
|
composition.RegisterUnique<PackageActionRunner>();
|
2019-01-11 10:35:37 +11:00
|
|
|
|
composition.RegisterUnique<ICreatedPackagesRepository>(factory =>
|
|
|
|
|
|
new CreatedPackagesRepository( //we are using a factory because there are optional ctor args
|
2019-01-10 17:18:47 +11:00
|
|
|
|
factory.GetInstance<IContentService>(), factory.GetInstance<IContentTypeService>(), factory.GetInstance<IDataTypeService>(),
|
|
|
|
|
|
factory.GetInstance<IFileService>(), factory.GetInstance<IMacroService>(), factory.GetInstance<ILocalizationService>(),
|
|
|
|
|
|
factory.GetInstance<IEntityXmlSerializer>(), factory.GetInstance<ILogger>()));
|
2019-01-10 12:44:57 +11:00
|
|
|
|
|
2018-07-20 09:49:05 +02:00
|
|
|
|
//TODO: These are replaced in the web project - we need to declare them so that
|
|
|
|
|
|
// something is wired up, just not sure this is very nice but will work for now.
|
2018-11-29 10:35:16 +01:00
|
|
|
|
composition.RegisterUnique<IApplicationTreeService, EmptyApplicationTreeService>();
|
|
|
|
|
|
composition.RegisterUnique<ISectionService, EmptySectionService>();
|
2018-07-20 15:45:01 +02:00
|
|
|
|
|
2018-11-27 10:37:33 +01:00
|
|
|
|
return composition;
|
2018-07-20 15:45:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-28 11:05:41 +01:00
|
|
|
|
private static LocalizedTextServiceFileSources SourcesFactory(IFactory container)
|
2018-07-20 15:45:01 +02:00
|
|
|
|
{
|
|
|
|
|
|
var mainLangFolder = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Umbraco + "/config/lang/"));
|
|
|
|
|
|
var appPlugins = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.AppPlugins));
|
|
|
|
|
|
var configLangFolder = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config + "/lang/"));
|
|
|
|
|
|
|
|
|
|
|
|
var pluginLangFolders = appPlugins.Exists == false
|
|
|
|
|
|
? Enumerable.Empty<LocalizedTextServiceSupplementaryFileSource>()
|
|
|
|
|
|
: appPlugins.GetDirectories()
|
|
|
|
|
|
.SelectMany(x => x.GetDirectories("Lang"))
|
|
|
|
|
|
.SelectMany(x => x.GetFiles("*.xml", SearchOption.TopDirectoryOnly))
|
|
|
|
|
|
.Where(x => Path.GetFileNameWithoutExtension(x.FullName).Length == 5)
|
|
|
|
|
|
.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)
|
|
|
|
|
|
.Where(x => Path.GetFileNameWithoutExtension(x.FullName).Length == 10)
|
|
|
|
|
|
.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(
|
|
|
|
|
|
container.GetInstance<ILogger>(),
|
|
|
|
|
|
container.GetInstance<CacheHelper>().RuntimeCache,
|
|
|
|
|
|
mainLangFolder,
|
|
|
|
|
|
pluginLangFolders.Concat(userLangFolders));
|
2018-07-20 09:49:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|