Files
Umbraco-CMS/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs

148 lines
8.7 KiB
C#
Raw Normal View History

using System;
2018-07-20 09:49:05 +02:00
using System.IO;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
2020-09-21 08:19:26 +02:00
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Packaging;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.Implement;
using Umbraco.Cms.Infrastructure.Packaging;
using Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement;
2021-11-02 09:18:15 +01:00
using Umbraco.Cms.Infrastructure.Services.Implement;
using Umbraco.Cms.Infrastructure.Templates;
using Umbraco.Extensions;
2018-07-20 09:49:05 +02:00
namespace Umbraco.Cms.Infrastructure.DependencyInjection
2018-07-20 09:49:05 +02:00
{
public static partial class UmbracoBuilderExtensions
2018-07-20 09:49:05 +02:00
{
/// <summary>
/// Adds Umbraco services
/// </summary>
internal static IUmbracoBuilder AddServices(this IUmbracoBuilder builder)
2018-07-20 09:49:05 +02:00
{
// register the service context
builder.Services.AddSingleton<ServiceContext>();
2018-07-20 09:49:05 +02:00
// register the special idk map
builder.Services.AddUnique<IIdKeyMap, IdKeyMap>();
2018-07-20 09:49:05 +02:00
// register the services
builder.Services.AddUnique<IPropertyValidationService, PropertyValidationService>();
builder.Services.AddUnique<IKeyValueService, KeyValueService>();
builder.Services.AddUnique<IPublicAccessService, PublicAccessService>();
builder.Services.AddUnique<IDomainService, DomainService>();
builder.Services.AddUnique<IAuditService, AuditService>();
builder.Services.AddUnique<ICacheInstructionService, CacheInstructionService>();
2021-08-06 09:51:08 +02:00
builder.Services.AddUnique<IBasicAuthService, BasicAuthService>();
builder.Services.AddUnique<ITagService, TagService>();
builder.Services.AddUnique<IContentService, ContentService>();
Merge remote-tracking branch 'origin/v8/feature/version-history-cleanup-ui' into v9/dev # Conflicts: # src/Umbraco.Core/Composing/CompositionExtensions/Repositories.cs # src/Umbraco.Core/Composing/CompositionExtensions/Services.cs # src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs # src/Umbraco.Core/Configuration/UmbracoSettings/IContentSection.cs # src/Umbraco.Core/ContentEditing/HistoryCleanup.cs # src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs # src/Umbraco.Core/Models/ContentType.cs # src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs # src/Umbraco.Core/Persistence/Repositories/DocumentVersionRepository.cs # src/Umbraco.Core/Scheduling/ContentVersionCleanup.cs # src/Umbraco.Core/Services/DefaultContentVersionCleanupPolicy.cs # src/Umbraco.Infrastructure/Migrations/Install/DatabaseSchemaCreator.cs # src/Umbraco.Infrastructure/Migrations/Upgrade/UmbracoPlan.cs # src/Umbraco.Infrastructure/Persistence/Repositories/Implement/ContentTypeCommonRepository.cs # src/Umbraco.Infrastructure/Services/Implement/ContentService.cs # src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.config # src/Umbraco.Tests/TestHelpers/Entities/MockedContent.cs # src/Umbraco.Tests/TestHelpers/Entities/MockedContentTypes.cs # src/Umbraco.Tests/Umbraco.Tests.csproj # src/Umbraco.Web.UI.Client/package-lock.json # src/Umbraco.Web.UI/config/umbracoSettings.Release.config # src/Umbraco.Web.UI/umbraco/config/lang/en.xml # src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml # src/Umbraco.Web/Scheduling/SchedulerComponent.cs # src/Umbraco.Web/Umbraco.Web.csproj # tests/Umbraco.Tests.Common/Extensions/AutoMoqDataAttribute.cs # tests/Umbraco.Tests.UnitTests/Umbraco.Core/Persistence/Repositories/DocumentVersionRepository_Tests_Integration.cs # tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scheduling/ContentVersionCleanup_Tests_UnitTests.cs # tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentVersionCleanupService_Tests_Integration.cs # tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentVersionCleanupService_Tests_UnitTests.cs # tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/DefaultContentVersionCleanupPolicy_Tests_UnitTests.cs
2021-10-29 15:00:27 +02:00
builder.Services.AddUnique<IContentVersionService, ContentVersionService>();
2021-11-02 09:18:15 +01:00
builder.Services.AddUnique<IContentVersionCleanupPolicy, DefaultContentVersionCleanupPolicy>();
builder.Services.AddUnique<IUserService, UserService>();
builder.Services.AddUnique<IMemberService, MemberService>();
builder.Services.AddUnique<IMediaService, MediaService>();
builder.Services.AddUnique<IContentTypeService, ContentTypeService>();
builder.Services.AddUnique<IContentTypeBaseServiceProvider, ContentTypeBaseServiceProvider>();
builder.Services.AddUnique<IMediaTypeService, MediaTypeService>();
builder.Services.AddUnique<IDataTypeService, DataTypeService>();
builder.Services.AddUnique<IFileService, FileService>();
builder.Services.AddUnique<ILocalizationService, LocalizationService>();
builder.Services.AddUnique<IPackagingService, PackagingService>();
builder.Services.AddUnique<IServerRegistrationService, ServerRegistrationService>();
builder.Services.AddUnique<IEntityService, EntityService>();
builder.Services.AddUnique<IRelationService, RelationService>();
Item tracking improvements (#11919) * Adding TrackedReferencesController * Adding/changing views * Adding/Editing js files * RelationService changes * RelationRepository changes * Adding missing translations * Adding/Modifying tests * Beginning of #9125 migration * Introducing a new component + refactoring based on that * Abstracting + refactoring * Work on content unpublishing * Work on media.delete * Various small changes * Beginning of #9119 migration * Changes on content.delete * Various fixes * Adding new keys used in the listview bulk actions * Adding methods to get the items used in relations from array of ids * Adding the checkLinkedItems function to the trackedReferencesResource * Passing the selected items from a listview to unpublish and delete * Adding umb-tracked-references-listview * Adding umb-tracked-references-listview-table with language column * Fixes for tracked references * Changes in listview unpublish dialog * Changes in listview delete dialog * Removing Variants logic as it is not currently supported * Visual fixes * Closing dialogs on click * Fix wording * Fix breaking changes * Change to a single title "Items in use" instead of 2 different for Content and Media * No need for obsoleting because we can change new controllers * Return ActionResult from actions * V9: Prevent delete or unpublish of items that have references (#12047) * Introducing config settings that prevent delete or unpublish of items referenced by other items * Disable deletion of content items and show a new warning * Disable deletion of media items and show a new warning * Disable deletion of list view items * Disable unpublish and bulk unpublish * Add a new warning * V9: Displaying descendants in use as part of item tracking (#12039) * Replace HasReferencesInDescendants with GetPagedDescendantsInReferences * Display descendants in use on parent's info tab * Add getPagedDescendantsInReferences to trackedReferencesResource * Add lang keys for Descendants in use * Refactoring controller actions * Don't call check descendants usage when it is a new item * rename busfy to busy * always show references * rearrange for scrollbar to appear at the edge of the dialog * use the word referenced instead of used * change fallback texts * Added "IsDependency" to relation types * refactor of umb-tracked-references * rename checkLinkedItems to getPagedReferencedItems * rename check to load, to be consistent with the rest. * Refactored backend . Needs frontend fixes * Cleanup * Use filters * Front-end refactor to match refactored end-points * Fixed bug + warning * Fixed query (more then 2100 descensdants) and optimized it (using nested select instead of inner join). * remove comment * hideNoneDependencies including varying text for the configuration * Hack for SqlCE :( * some final adjustments for item tracking ui * Unbreak change Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com> Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2022-03-07 22:46:16 +01:00
builder.Services.AddUnique<ITrackedReferencesService, TrackedReferencesService>();
builder.Services.AddUnique<IMacroService, MacroService>();
builder.Services.AddUnique<IMemberTypeService, MemberTypeService>();
builder.Services.AddUnique<IMemberGroupService, MemberGroupService>();
builder.Services.AddUnique<INotificationService, NotificationService>();
builder.Services.AddUnique<ExternalLoginService>(factory => new ExternalLoginService(
factory.GetRequiredService<IScopeProvider>(),
factory.GetRequiredService<ILoggerFactory>(),
factory.GetRequiredService<IEventMessagesFactory>(),
factory.GetRequiredService<IExternalLoginWithKeyRepository>()
));
builder.Services.AddUnique<IExternalLoginService>(factory => factory.GetRequiredService<ExternalLoginService>());
builder.Services.AddUnique<IExternalLoginWithKeyService>(factory => factory.GetRequiredService<ExternalLoginService>());
Member 2FA (#11889) * Bugfix - Take ufprt from form data if the request has form content type, otherwise fallback to use the query * External linking for members * Changed migration to reuse old table * removed unnecessary web.config files * Cleanup * Extracted class to own file * Clean up * Rollback changes to Umbraco.Web.UI.csproj * Fixed migration for SqlCE * Added 2fa for members * Change notification handler to be on deleted * Update src/Umbraco.Infrastructure/Security/MemberUserStore.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * updated snippets * Fixed issue with errors not shown on member linking * fixed issue with errors * clean up * Fix issue where external logins could not be used to upgrade Umbraco, because the externalLogin table was expected to look different. (Like after the migration) * Fixed issue in Ignore legacy column now using result column. * Updated 2fa for members + publish notification when 2fa is requested. * Changed so only Members out of box supports 2fa * Cleanup * rollback of csproj file, that should not have been changed * Removed confirmed flag from db. It was not used. Handle case where a user is signed up for 2fa, but the provider do not exist anymore. Then it is just ignored until it shows up again Reintroduced ProviderName on interface, to ensure the class can be renamed safely * Bugfix * Registering DeleteTwoFactorLoginsOnMemberDeletedHandler * Rollback nuget packages added by mistake * Update src/Umbraco.Infrastructure/Services/Implement/TwoFactorLoginService.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TwoFactorLoginRepository.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Added providername to snippet Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
2022-01-21 13:10:34 +01:00
builder.Services.AddUnique<ITwoFactorLoginService, TwoFactorLoginService>();
builder.Services.AddUnique<IRedirectUrlService, RedirectUrlService>();
builder.Services.AddUnique<IConsentService, ConsentService>();
builder.Services.AddTransient(SourcesFactory);
builder.Services.AddUnique<ILocalizedTextService>(factory => new LocalizedTextService(
factory.GetRequiredService<Lazy<LocalizedTextServiceFileSources>>(),
factory.GetRequiredService<ILogger<LocalizedTextService>>()));
2018-07-20 09:49:05 +02:00
builder.Services.AddUnique<IEntityXmlSerializer, EntityXmlSerializer>();
builder.Services.AddSingleton<ConflictingPackageData>();
builder.Services.AddSingleton<CompiledPackageXmlParser>();
builder.Services.AddUnique(factory => CreatePackageRepository(factory, "createdPackages.config"));
builder.Services.AddUnique<ICreatedPackagesRepository, CreatedPackageSchemaRepository>();
builder.Services.AddSingleton<PackageDataInstallation>();
builder.Services.AddUnique<IPackageInstallation, PackageInstallation>();
builder.Services.AddUnique<IHtmlMacroParameterParser, HtmlMacroParameterParser>();
return builder;
2018-07-20 15:45:01 +02:00
}
private static PackagesRepository CreatePackageRepository(IServiceProvider factory, string packageRepoFileName)
2019-01-18 10:02:47 +01:00
=> new PackagesRepository(
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);
private static LocalizedTextServiceFileSources SourcesFactory(IServiceProvider container)
2018-07-20 15:45:01 +02:00
{
var hostingEnvironment = container.GetRequiredService<IHostingEnvironment>();
var globalSettings = container.GetRequiredService<IOptions<GlobalSettings>>().Value;
var mainLangFolder = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(WebPath.Combine(Constants.SystemDirectories.Umbraco, "config", "lang")));
var appPlugins = new DirectoryInfo(hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins));
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()
// Check for both Lang & lang to support case sensitive file systems.
.SelectMany(x => x.GetDirectories("?ang", SearchOption.AllDirectories).Where(x => x.Name.InvariantEquals("lang")))
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
2018-07-20 15:45:01 +02:00
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(
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
}
}
}