diff --git a/src/Umbraco.Core/DependencyInjection/Current.cs b/src/Umbraco.Core/DependencyInjection/Current.cs index 67013b5318..d8f1035775 100644 --- a/src/Umbraco.Core/DependencyInjection/Current.cs +++ b/src/Umbraco.Core/DependencyInjection/Current.cs @@ -1,6 +1,7 @@ using System; using LightInject; using Umbraco.Core.Cache; +using Umbraco.Core.Dictionary; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Strings; @@ -74,6 +75,9 @@ namespace Umbraco.Core.DependencyInjection public static IServerRegistrar ServerRegistrar => Container.GetInstance(); + public static ICultureDictionaryFactory CultureDictionaryFactory + => Container.GetInstance(); + #endregion } } diff --git a/src/Umbraco.Core/Dictionary/CultureDictionaryFactoryResolver.cs b/src/Umbraco.Core/Dictionary/CultureDictionaryFactoryResolver.cs deleted file mode 100644 index bda3992ff6..0000000000 --- a/src/Umbraco.Core/Dictionary/CultureDictionaryFactoryResolver.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Linq.Expressions; -using System.ComponentModel; -using LightInject; -using Umbraco.Core.ObjectResolution; - -namespace Umbraco.Core.Dictionary -{ - /// - /// Resolves the current CultureDictionaryFactory - /// - public sealed class CultureDictionaryFactoryResolver : ContainerSingleObjectResolver - { - /// - /// Initializes the resolver to use IoC - /// - /// - internal CultureDictionaryFactoryResolver(IServiceContainer container) - : base(container) - { } - - internal CultureDictionaryFactoryResolver(ICultureDictionaryFactory factory) - : base(factory) - { - } - - /// - /// Initializes the resolver to use IoC - /// - /// - /// - internal CultureDictionaryFactoryResolver(IServiceContainer container, Func implementationType) - : base(container, implementationType) - { - } - - /// - /// Can be used by developers at runtime to set their ICultureDictionaryFactory at app startup - /// - /// - public void SetDictionaryFactory(ICultureDictionaryFactory factory) - { - Value = factory; - } - - /// - /// Returns the ICultureDictionaryFactory - /// - public ICultureDictionaryFactory Factory - { - get { return Value; } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs b/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs index c5c297394e..185d1f217d 100644 --- a/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs +++ b/src/Umbraco.Core/Services/LocalizedTextServiceExtensions.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Linq; using System.Threading; +using Umbraco.Core.DependencyInjection; using Umbraco.Core.Dictionary; namespace Umbraco.Core.Services @@ -97,13 +98,7 @@ namespace Umbraco.Core.Services return cultureDictionary[text].IfNullOrWhiteSpace(text); } - private static ICultureDictionary CultureDictionary - { - get - { - return _cultureDictionary - ?? (_cultureDictionary = CultureDictionaryFactoryResolver.Current.Factory.CreateDictionary()); - } - } + private static ICultureDictionary CultureDictionary + => _cultureDictionary ?? (_cultureDictionary = Current.CultureDictionaryFactory.CreateDictionary()); } } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 52529b1333..f016c8eb3f 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -228,7 +228,6 @@ - diff --git a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs index 78099dad9b..c03cf341e8 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentWebModelMappingTests.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Globalization; +using System.Globalization; using System.Linq; -using System.Text; -using System.Threading.Tasks; using AutoMapper; using Moq; using NUnit.Framework; @@ -15,11 +11,9 @@ using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; -using Umbraco.Web.Dictionary; using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.Models.Mapping; -using umbraco; -using Umbraco.Web; +using Umbraco.Core.DependencyInjection; +using Current = Umbraco.Web.Current; namespace Umbraco.Tests.Models.Mapping { @@ -30,8 +24,7 @@ namespace Umbraco.Tests.Models.Mapping { protected override void FreezeResolution() { - CultureDictionaryFactoryResolver.Current = new CultureDictionaryFactoryResolver( - Mock.Of()); + Container.RegisterSingleton(_ => Mock.Of()); base.FreezeResolution(); } diff --git a/src/Umbraco.Web/Current.cs b/src/Umbraco.Web/Current.cs index 09b0e533ca..3576c5c7a3 100644 --- a/src/Umbraco.Web/Current.cs +++ b/src/Umbraco.Web/Current.cs @@ -2,6 +2,7 @@ using LightInject; using Umbraco.Core; using Umbraco.Core.Cache; +using Umbraco.Core.Dictionary; using Umbraco.Core.Events; using Umbraco.Core.Macros; using Umbraco.Core.Models.PublishedContent; @@ -228,6 +229,9 @@ namespace Umbraco.Web public static IServerRegistrar ServerRegistrar => Container.GetInstance(); + public static ICultureDictionaryFactory CultureDictionaryFactory + => Container.GetInstance(); + #endregion } } diff --git a/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs b/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs index 62bf5092e0..d19251346d 100644 --- a/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs +++ b/src/Umbraco.Web/Editors/ContentTypeControllerBase.cs @@ -463,15 +463,6 @@ namespace Umbraco.Web.Editors } private ICultureDictionary CultureDictionary - { - get - { - return - _cultureDictionary ?? - (_cultureDictionary = CultureDictionaryFactoryResolver.Current.Factory.CreateDictionary()); - } - } - - + => _cultureDictionary ?? (_cultureDictionary = Current.CultureDictionaryFactory.CreateDictionary()); } } \ No newline at end of file diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index 8ac22da688..92e27f1e0a 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -262,8 +262,7 @@ namespace Umbraco.Web { if (_cultureDictionary == null) { - var factory = CultureDictionaryFactoryResolver.Current.Factory; - _cultureDictionary = factory.CreateDictionary(); + _cultureDictionary = Current.CultureDictionaryFactory.CreateDictionary(); } return _cultureDictionary; } diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 696e959088..60f9cf70ef 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -529,8 +529,7 @@ namespace Umbraco.Web ImageUrlProviderCollectionBuilder.Register(Container) .Append(PluginManager.ResolveImageUrlProviders()); - CultureDictionaryFactoryResolver.Current = new CultureDictionaryFactoryResolver(Container); - Container.Register(); + Container.RegisterSingleton(); HealthCheckCollectionBuilder.Register(Container) .AddProducer(() => PluginManager.ResolveTypes())