Resvolution - PublishedContentModelFactoryResolver
This commit is contained in:
@@ -461,9 +461,8 @@ namespace Umbraco.Core
|
||||
UrlSegmentProviderCollectionBuilder.Register(Container)
|
||||
.Append<DefaultUrlSegmentProvider>();
|
||||
|
||||
// by default, no factory is activated
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(Container);
|
||||
// by default, no factory (ie, noop) is activated
|
||||
Container.RegisterSingleton<IPublishedContentModelFactory, NoopPublishedContentModelFactory>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<PropertyValueConverterCollection>();
|
||||
|
||||
internal static IPublishedContentModelFactory PublishedContentModelFactory
|
||||
=> Container.GetInstance<IPublishedContentModelFactory>();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
public class NoopPublishedContentModelFactory : IPublishedContentModelFactory
|
||||
{
|
||||
public IPublishedContent CreateModel(IPublishedContent content)
|
||||
{
|
||||
return content;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.");
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using LightInject;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolves the IPublishedContentModelFactory object.
|
||||
/// </summary>
|
||||
public class PublishedContentModelFactoryResolver : ContainerSingleObjectResolver<PublishedContentModelFactoryResolver, IPublishedContentModelFactory>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PublishedContentModelFactoryResolver"/>.
|
||||
/// </summary>
|
||||
/// <remarks>The resolver is created by the <c>WebBootManager</c> and thus the constructor remains internal.</remarks>
|
||||
internal PublishedContentModelFactoryResolver()
|
||||
: base()
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PublishedContentModelFactoryResolver"/> with a factory.
|
||||
/// </summary>
|
||||
/// <param name="factory">The factory.</param>
|
||||
/// <remarks>The resolver is created by the <c>WebBootManager</c> and thus the constructor remains internal.</remarks>
|
||||
internal PublishedContentModelFactoryResolver(IPublishedContentModelFactory factory)
|
||||
: base(factory)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
internal PublishedContentModelFactoryResolver(IServiceContainer container)
|
||||
: base(container)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Sets the factory.
|
||||
/// </summary>
|
||||
/// <param name="factory">The factory.</param>
|
||||
/// <remarks>For developers, at application startup.</remarks>
|
||||
public void SetFactory(IPublishedContentModelFactory factory)
|
||||
{
|
||||
Value = factory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the factory.
|
||||
/// </summary>
|
||||
public IPublishedContentModelFactory Factory
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,6 +270,7 @@
|
||||
<Compile Include="Macros\XsltExtensionCollectionBuilder.cs" />
|
||||
<Compile Include="Models\DictionaryItemExtensions.cs" />
|
||||
<Compile Include="Models\PublishedContent\IPublishedFragment.cs" />
|
||||
<Compile Include="Models\PublishedContent\NoopPublishedContentModelFactory.cs" />
|
||||
<Compile Include="Models\PublishedContent\PropertyResult.cs" />
|
||||
<Compile Include="Models\PublishedContent\PropertyResultType.cs" />
|
||||
<Compile Include="Persistence\IUmbracoDatabaseAccessor.cs" />
|
||||
@@ -576,7 +577,6 @@
|
||||
<Compile Include="Models\PublishedContent\PublishedContentModelFactory.cs" />
|
||||
<Compile Include="Models\PublishedContent\IPublishedContentModelFactory.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentModel.cs" />
|
||||
<Compile Include="Models\PublishedContent\PublishedContentModelFactoryResolver.cs" />
|
||||
<Compile Include="Models\PartialView.cs" />
|
||||
<Compile Include="Models\Rdbms\CacheInstructionDto.cs" />
|
||||
<Compile Include="Models\TagCacheStorageType.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()
|
||||
{
|
||||
|
||||
@@ -33,7 +33,6 @@ namespace Umbraco.Tests.Cache.PublishedCache
|
||||
UrlSegmentProviderCollectionBuilder.Register(Container)
|
||||
.Append<DefaultUrlSegmentProvider>();
|
||||
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();
|
||||
base.FreezeResolution();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<PublishedContentModel>();
|
||||
PublishedContentModelFactoryResolver.Current =
|
||||
new PublishedContentModelFactoryResolver(new PublishedContentModelFactory(types));
|
||||
Container.RegisterSingleton<IPublishedContentModelFactory>(_ => 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<string>(), props);
|
||||
|
||||
@@ -38,9 +38,6 @@ namespace Umbraco.Tests.PublishedContent
|
||||
.Append<TinyMceValueConverter>()
|
||||
.Append<YesNoValueConverter>();
|
||||
|
||||
if (PublishedContentModelFactoryResolver.HasCurrent == false)
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();
|
||||
|
||||
base.FreezeResolution();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<PublishedContentModel>();
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(
|
||||
new PublishedContentModelFactory(types));
|
||||
base.FreezeResolution();
|
||||
Container.RegisterSingleton<IPublishedContentModelFactory>(_ => new PublishedContentModelFactory(types));
|
||||
|
||||
base.FreezeResolution();
|
||||
}
|
||||
|
||||
protected override string GetXmlContent(int templateId)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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<IFileSystem>(factory => Mock.Of<IFileSystem>(), "ViewFileSystem");
|
||||
Container.RegisterSingleton<IFileSystem>(factory => new PhysicalFileSystem("Views", "/views"), "ViewFileSystem");
|
||||
Container.RegisterSingleton<IFileSystem>(factory => new PhysicalFileSystem("MasterPages", "/masterpages"), "MasterpageFileSystem");
|
||||
|
||||
// no factory (noop)
|
||||
Container.RegisterSingleton<IPublishedContentModelFactory, NoopPublishedContentModelFactory>();
|
||||
}
|
||||
|
||||
private static readonly object Locker = new object();
|
||||
|
||||
@@ -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<PropertyValueConverterCollection>();
|
||||
|
||||
internal static IPublishedContentModelFactory PublishedContentModelFactory
|
||||
=> Container.GetInstance<IPublishedContentModelFactory>();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user