From 73bb9e3279572724a8032e95f711994cf65c99a8 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 25 Nov 2019 23:10:54 +1100 Subject: [PATCH] Moves culture dictionary implementation to Core instead of web since it has nothing to do with Web really, fixes tests --- .../Composing/CompositionExtensions/Services.cs | 1 + .../Dictionary/UmbracoCultureDictionary.cs | 5 ++--- .../Dictionary/UmbracoCultureDictionaryFactory.cs | 6 +++--- .../Repositories/Implement/UserRepository.cs | 6 +++--- src/Umbraco.Core/Runtime/CoreInitialComposer.cs | 3 +++ src/Umbraco.Core/Umbraco.Core.csproj | 2 ++ .../Models/Mapping/ContentWebModelMappingTests.cs | 3 --- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- src/Umbraco.Web/Editors/AuthenticationController.cs | 2 +- src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs | 2 +- src/Umbraco.Web/Models/Mapping/MemberMapDefinition.cs | 4 +--- src/Umbraco.Web/Runtime/WebFinalComposer.cs | 10 ---------- src/Umbraco.Web/Runtime/WebInitialComposer.cs | 3 --- src/Umbraco.Web/Umbraco.Web.csproj | 2 -- 14 files changed, 18 insertions(+), 33 deletions(-) rename src/{Umbraco.Web => Umbraco.Core}/Dictionary/UmbracoCultureDictionary.cs (97%) rename src/{Umbraco.Web => Umbraco.Core}/Dictionary/UmbracoCultureDictionaryFactory.cs (79%) diff --git a/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs index ba8442f8d7..b0cd80d93f 100644 --- a/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs +++ b/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; +using Umbraco.Core.Dictionary; using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Logging; diff --git a/src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs b/src/Umbraco.Core/Dictionary/UmbracoCultureDictionary.cs similarity index 97% rename from src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs rename to src/Umbraco.Core/Dictionary/UmbracoCultureDictionary.cs index f11b2dcfcb..b0690c944b 100644 --- a/src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs +++ b/src/Umbraco.Core/Dictionary/UmbracoCultureDictionary.cs @@ -5,9 +5,8 @@ using System.Linq; using Umbraco.Core.Cache; using Umbraco.Core.Models; using Umbraco.Core.Services; -using Umbraco.Web.Composing; -namespace Umbraco.Web.Dictionary +namespace Umbraco.Core.Dictionary { /// @@ -18,7 +17,7 @@ namespace Umbraco.Web.Dictionary /// The ILocalizationService is the service used for interacting with this data from the database which isn't all that fast /// (even though there is caching involved, if there's lots of dictionary items the caching is not great) /// - public class DefaultCultureDictionary : Core.Dictionary.ICultureDictionary + public class DefaultCultureDictionary : ICultureDictionary { private readonly ILocalizationService _localizationService; private readonly IAppCache _requestCache; diff --git a/src/Umbraco.Web/Dictionary/UmbracoCultureDictionaryFactory.cs b/src/Umbraco.Core/Dictionary/UmbracoCultureDictionaryFactory.cs similarity index 79% rename from src/Umbraco.Web/Dictionary/UmbracoCultureDictionaryFactory.cs rename to src/Umbraco.Core/Dictionary/UmbracoCultureDictionaryFactory.cs index d66bd99f83..a2d1fa12d3 100644 --- a/src/Umbraco.Web/Dictionary/UmbracoCultureDictionaryFactory.cs +++ b/src/Umbraco.Core/Dictionary/UmbracoCultureDictionaryFactory.cs @@ -1,7 +1,7 @@ using Umbraco.Core.Cache; using Umbraco.Core.Services; -namespace Umbraco.Web.Dictionary +namespace Umbraco.Core.Dictionary { /// /// A culture dictionary factory used to create an Umbraco.Core.Dictionary.ICultureDictionary. @@ -9,7 +9,7 @@ namespace Umbraco.Web.Dictionary /// /// In the future this will allow use to potentially store dictionary items elsewhere and allows for maximum flexibility. /// - internal class DefaultCultureDictionaryFactory : Umbraco.Core.Dictionary.ICultureDictionaryFactory + internal class DefaultCultureDictionaryFactory : ICultureDictionaryFactory { private readonly ILocalizationService _localizationService; private readonly AppCaches _appCaches; @@ -20,7 +20,7 @@ namespace Umbraco.Web.Dictionary _appCaches = appCaches; } - public Umbraco.Core.Dictionary.ICultureDictionary CreateDictionary() + public ICultureDictionary CreateDictionary() { return new DefaultCultureDictionary(_localizationService, _appCaches.RequestCache); } diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/UserRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/UserRepository.cs index 757ea6eb30..ff8beecff5 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/UserRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/UserRepository.cs @@ -42,9 +42,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement public UserRepository(IScopeAccessor scopeAccessor, AppCaches appCaches, ILogger logger, IMapperCollection mapperCollection, IGlobalSettings globalSettings, IUserPasswordConfiguration passwordConfiguration) : base(scopeAccessor, appCaches, logger) { - _mapperCollection = mapperCollection; - _globalSettings = globalSettings; - _passwordConfiguration = passwordConfiguration; + _mapperCollection = mapperCollection ?? throw new ArgumentNullException(nameof(mapperCollection)); + _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); + _passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration)); } /// diff --git a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs index bf28898820..0a2e39592f 100644 --- a/src/Umbraco.Core/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Core/Runtime/CoreInitialComposer.cs @@ -4,6 +4,7 @@ using Umbraco.Core.Composing; using Umbraco.Core.Composing.CompositionExtensions; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Dictionary; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Manifest; @@ -132,6 +133,8 @@ namespace Umbraco.Core.Runtime // by default, register a noop rebuilder composition.RegisterUnique(); + composition.SetCultureDictionaryFactory(); + composition.Register(f => f.GetInstance().CreateDictionary(), Lifetime.Singleton); composition.RegisterUnique(); } } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 6c28c9d68b..931d5ec023 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -147,6 +147,8 @@ + + diff --git a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs index 9a47ad1b4a..66d3b570b0 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs @@ -31,9 +31,6 @@ namespace Umbraco.Tests.Models.Mapping { base.Compose(); - Composition.RegisterUnique(f => Mock.Of()); - - Composition.Register(_ => Mock.Of()); Composition.ComposeFileSystems(); Composition.Register(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index a321ce90cc..4fb488c3e4 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -42,7 +42,6 @@ using Umbraco.Web.Composing.CompositionExtensions; using Umbraco.Web.Sections; using Current = Umbraco.Core.Composing.Current; using FileSystems = Umbraco.Core.IO.FileSystems; -using Umbraco.Web.Dictionary; using Umbraco.Core.Dictionary; namespace Umbraco.Tests.Testing @@ -325,6 +324,7 @@ namespace Umbraco.Tests.Testing { Composition.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings); Composition.Configs.Add(SettingsForTests.GetDefaultGlobalSettings); + //Composition.Configs.Add(() => new DefaultUserPasswordConfig()); } protected virtual void ComposeApplication(bool withApplication) diff --git a/src/Umbraco.Web/Editors/AuthenticationController.cs b/src/Umbraco.Web/Editors/AuthenticationController.cs index 2551d33c6e..c77b24e607 100644 --- a/src/Umbraco.Web/Editors/AuthenticationController.cs +++ b/src/Umbraco.Web/Editors/AuthenticationController.cs @@ -46,7 +46,7 @@ namespace Umbraco.Web.Editors public AuthenticationController(IUserPasswordConfiguration passwordConfiguration, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, UmbracoMapper umbracoMapper) : base(globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, umbracoMapper) { - _passwordConfiguration = passwordConfiguration; + _passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration)); } protected BackOfficeUserManager UserManager => _userManager diff --git a/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs b/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs index aeddb167e0..7f4ff496f1 100644 --- a/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs +++ b/src/Umbraco.Web/Install/InstallSteps/NewInstallStep.cs @@ -43,7 +43,7 @@ namespace Umbraco.Web.Install.InstallSteps _userService = userService; _databaseBuilder = databaseBuilder; _globalSettings = globalSettings; - _passwordConfiguration = passwordConfiguration; + _passwordConfiguration = passwordConfiguration ?? throw new ArgumentNullException(nameof(passwordConfiguration)); _userManager = _http.GetOwinContext().GetBackOfficeUserManager(); } diff --git a/src/Umbraco.Web/Models/Mapping/MemberMapDefinition.cs b/src/Umbraco.Web/Models/Mapping/MemberMapDefinition.cs index f93c1208ed..e6185ab80e 100644 --- a/src/Umbraco.Web/Models/Mapping/MemberMapDefinition.cs +++ b/src/Umbraco.Web/Models/Mapping/MemberMapDefinition.cs @@ -21,13 +21,11 @@ namespace Umbraco.Web.Models.Mapping internal class MemberMapDefinition : IMapDefinition { private readonly CommonMapper _commonMapper; - private readonly IMemberTypeService _memberTypeService; private readonly MemberTabsAndPropertiesMapper _tabsAndPropertiesMapper; - public MemberMapDefinition(CommonMapper commonMapper, IMemberTypeService memberTypeService, MemberTabsAndPropertiesMapper tabsAndPropertiesMapper) + public MemberMapDefinition(CommonMapper commonMapper, MemberTabsAndPropertiesMapper tabsAndPropertiesMapper) { _commonMapper = commonMapper; - _memberTypeService = memberTypeService; _tabsAndPropertiesMapper = tabsAndPropertiesMapper; } diff --git a/src/Umbraco.Web/Runtime/WebFinalComposer.cs b/src/Umbraco.Web/Runtime/WebFinalComposer.cs index f0178413a0..3f9fd2bbc4 100644 --- a/src/Umbraco.Web/Runtime/WebFinalComposer.cs +++ b/src/Umbraco.Web/Runtime/WebFinalComposer.cs @@ -10,15 +10,5 @@ namespace Umbraco.Web.Runtime [ComposeAfter(typeof(ICoreComposer))] public class WebFinalComposer : ComponentComposer { - - public override void Compose(Composition composition) - { - base.Compose(composition); - - // now that user composers have had a chance to register their own factory, we can add the result of the factory - // to the container. - composition.Register(f => f.GetInstance().CreateDictionary(), Lifetime.Singleton); - } - } } diff --git a/src/Umbraco.Web/Runtime/WebInitialComposer.cs b/src/Umbraco.Web/Runtime/WebInitialComposer.cs index 92236ae96a..f475ac9e78 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComposer.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComposer.cs @@ -20,7 +20,6 @@ using Umbraco.Web.Cache; using Umbraco.Web.Composing.CompositionExtensions; using Umbraco.Web.ContentApps; using Umbraco.Web.Dashboards; -using Umbraco.Web.Dictionary; using Umbraco.Web.Editors; using Umbraco.Web.Features; using Umbraco.Web.HealthCheck; @@ -202,8 +201,6 @@ namespace Umbraco.Web.Runtime composition.RegisterUnique(); - composition.SetCultureDictionaryFactory(); - // register *all* checks, except those marked [HideFromTypeFinder] of course composition.WithCollectionBuilder() .Add(() => composition.TypeLoader.GetTypes()); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 533eae8eee..25337d09d8 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -1044,8 +1044,6 @@ - -