diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 80b4839bcf..36cda7ed75 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -461,9 +461,8 @@ namespace Umbraco.Core UrlSegmentProviderCollectionBuilder.Register(Container) .Append(); - // by default, no factory is activated - PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(Container); + // by default, no factory (ie, noop) is activated + Container.RegisterSingleton(); } - } } diff --git a/src/Umbraco.Core/DependencyInjection/Current.cs b/src/Umbraco.Core/DependencyInjection/Current.cs index 69c3b658ea..6baa0aa06c 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.Models.PublishedContent; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Strings; using Umbraco.Core._Legacy.PackageActions; @@ -63,6 +64,9 @@ namespace Umbraco.Core.DependencyInjection internal static PropertyValueConverterCollection PropertyValueConverters => Container.GetInstance(); + internal static IPublishedContentModelFactory PublishedContentModelFactory + => Container.GetInstance(); + #endregion } } diff --git a/src/Umbraco.Core/Models/PublishedContent/NoopPublishedContentModelFactory.cs b/src/Umbraco.Core/Models/PublishedContent/NoopPublishedContentModelFactory.cs new file mode 100644 index 0000000000..a92427191e --- /dev/null +++ b/src/Umbraco.Core/Models/PublishedContent/NoopPublishedContentModelFactory.cs @@ -0,0 +1,10 @@ +namespace Umbraco.Core.Models.PublishedContent +{ + public class NoopPublishedContentModelFactory : IPublishedContentModelFactory + { + public IPublishedContent CreateModel(IPublishedContent content) + { + return content; + } + } +} diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtensionsForModels.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtensionsForModels.cs index 08d04da1eb..012f0ada5c 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtensionsForModels.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentExtensionsForModels.cs @@ -1,4 +1,5 @@ using System; +using Umbraco.Core.DependencyInjection; namespace Umbraco.Core.Models.PublishedContent { @@ -17,13 +18,9 @@ namespace Umbraco.Core.Models.PublishedContent if (content == null) return null; - if (PublishedContentModelFactoryResolver.Current.HasValue == false) - return content; - // get model // if factory returns nothing, throw - // if factory just returns what it got, return - var model = PublishedContentModelFactoryResolver.Current.Factory.CreateModel(content); + var model = Current.PublishedContentModelFactory.CreateModel(content); if (model == null) throw new Exception("IPublishedContentFactory returned null."); diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentModelFactoryResolver.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentModelFactoryResolver.cs deleted file mode 100644 index 23621e432f..0000000000 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentModelFactoryResolver.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using LightInject; -using Umbraco.Core.ObjectResolution; - -namespace Umbraco.Core.Models.PublishedContent -{ - /// - /// Resolves the IPublishedContentModelFactory object. - /// - public class PublishedContentModelFactoryResolver : ContainerSingleObjectResolver - { - /// - /// Initializes a new instance of the . - /// - /// The resolver is created by the WebBootManager and thus the constructor remains internal. - internal PublishedContentModelFactoryResolver() - : base() - { } - - /// - /// Initializes a new instance of the with a factory. - /// - /// The factory. - /// The resolver is created by the WebBootManager and thus the constructor remains internal. - internal PublishedContentModelFactoryResolver(IPublishedContentModelFactory factory) - : base(factory) - { } - - /// - /// Initialize the resolver to use IoC - /// - /// - internal PublishedContentModelFactoryResolver(IServiceContainer container) - : base(container) - { } - - /// - /// Sets the factory. - /// - /// The factory. - /// For developers, at application startup. - public void SetFactory(IPublishedContentModelFactory factory) - { - Value = factory; - } - - /// - /// Gets the factory. - /// - public IPublishedContentModelFactory Factory - { - get { return Value; } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 8c32f10f94..a26b0e0b65 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -270,6 +270,7 @@ + @@ -576,7 +577,6 @@ - diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs index b2c754b077..3f3644b8ae 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs @@ -80,13 +80,6 @@ namespace Umbraco.Tests.Cache.PublishedCache _cache = _umbracoContext.ContentCache; } - protected override void FreezeResolution() - { - PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(); - base.FreezeResolution(); - } - - [Test] public void Has_Content() { diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs index ac4f2f99a0..e2bcc2a9b1 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs @@ -33,7 +33,6 @@ namespace Umbraco.Tests.Cache.PublishedCache UrlSegmentProviderCollectionBuilder.Register(Container) .Append(); - PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(); base.FreezeResolution(); } diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs index 7d0fadec70..f3d6955591 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs @@ -5,19 +5,15 @@ using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; -using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; -using Umbraco.Core.ObjectResolution; using Umbraco.Core.PropertyEditors; using Umbraco.Web; -using Umbraco.Tests.TestHelpers; -using umbraco.BusinessLogic; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Plugins; using Umbraco.Web.PublishedCache; -using Umbraco.Web.PublishedCache.XmlPublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; +using Umbraco.Core.DependencyInjection; namespace Umbraco.Tests.PublishedContent { @@ -49,9 +45,9 @@ namespace Umbraco.Tests.PublishedContent protected override void FreezeResolution() { PropertyValueConverterCollectionBuilder.Register(Container); + var types = PluginManager.Current.ResolveTypes(); - PublishedContentModelFactoryResolver.Current = - new PublishedContentModelFactoryResolver(new PublishedContentModelFactory(types)); + Container.RegisterSingleton(_ => new PublishedContentModelFactory(types)); base.FreezeResolution(); } @@ -75,7 +71,7 @@ namespace Umbraco.Tests.PublishedContent Umbraco.Web.Current.SetUmbracoContext(ctx, true); } - + public override void TearDown() { base.TearDown(); @@ -202,7 +198,7 @@ namespace Umbraco.Tests.PublishedContent var props = new[] { - new PublishedPropertyType("prop1", 1, "?"), + new PublishedPropertyType("prop1", 1, "?"), }; var contentType1 = new PublishedContentType(1, "ContentType1", Enumerable.Empty(), props); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs index 3ddc0168cf..a9cd32d4a8 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs @@ -38,9 +38,6 @@ namespace Umbraco.Tests.PublishedContent .Append() .Append(); - if (PublishedContentModelFactoryResolver.HasCurrent == false) - PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(); - base.FreezeResolution(); } } diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index 6269e0f768..8cb3f2cf05 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Plugins; using Umbraco.Core.PropertyEditors; using Umbraco.Web; using Umbraco.Web.PublishedCache; +using Umbraco.Core.DependencyInjection; namespace Umbraco.Tests.PublishedContent { @@ -65,9 +66,9 @@ namespace Umbraco.Tests.PublishedContent protected override void FreezeResolution() { var types = PluginManager.Current.ResolveTypes(); - PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver( - new PublishedContentModelFactory(types)); - base.FreezeResolution(); + Container.RegisterSingleton(_ => new PublishedContentModelFactory(types)); + + base.FreezeResolution(); } protected override string GetXmlContent(int templateId) diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index 0cf740cad9..329fbbbec6 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -265,9 +265,6 @@ namespace Umbraco.Tests.TestHelpers // fixme - what about if (PropertyValueConvertersResolver.HasCurrent == false) ?? PropertyValueConverterCollectionBuilder.Register(Container); - if (PublishedContentModelFactoryResolver.HasCurrent == false) - PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(); - // ensure we have a FacadeService if (_facadeService == null) { diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index 9d01fd1eea..279f382923 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -23,6 +23,7 @@ using Umbraco.Web; using Umbraco.Core.DependencyInjection; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Events; +using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Plugins; using Umbraco.Web.DependencyInjection; using UmbracoExamine; @@ -130,6 +131,9 @@ namespace Umbraco.Tests.TestHelpers //Container.RegisterSingleton(factory => Mock.Of(), "ViewFileSystem"); Container.RegisterSingleton(factory => new PhysicalFileSystem("Views", "/views"), "ViewFileSystem"); Container.RegisterSingleton(factory => new PhysicalFileSystem("MasterPages", "/masterpages"), "MasterpageFileSystem"); + + // no factory (noop) + Container.RegisterSingleton(); } private static readonly object Locker = new object(); diff --git a/src/Umbraco.Web/Current.cs b/src/Umbraco.Web/Current.cs index a76fe78414..de7d56435f 100644 --- a/src/Umbraco.Web/Current.cs +++ b/src/Umbraco.Web/Current.cs @@ -4,6 +4,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Events; using Umbraco.Core.Macros; +using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Persistence.Migrations; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Strings; @@ -217,6 +218,9 @@ namespace Umbraco.Web internal static PropertyValueConverterCollection PropertyValueConverters => Container.GetInstance(); + internal static IPublishedContentModelFactory PublishedContentModelFactory + => Container.GetInstance(); + #endregion } }