diff --git a/src/Umbraco.Core/Models/PublishedContent/ILivePublishedModelFactory.cs b/src/Umbraco.Core/Models/PublishedContent/ILivePublishedModelFactory.cs index 0810f2207b..0d7744389a 100644 --- a/src/Umbraco.Core/Models/PublishedContent/ILivePublishedModelFactory.cs +++ b/src/Umbraco.Core/Models/PublishedContent/ILivePublishedModelFactory.cs @@ -1,5 +1,16 @@ namespace Umbraco.Core.Models.PublishedContent { + /// + /// Provides a live published model creation service. + /// + public interface ILivePublishedModelFactory2 : ILivePublishedModelFactory + { + /// + /// Tells the factory that it should build a new generation of models + /// + void Reset(); + } + /// /// Provides a live published model creation service. /// diff --git a/src/Umbraco.Core/PublishedModelFactoryExtensions.cs b/src/Umbraco.Core/PublishedModelFactoryExtensions.cs index ac8c9f1be7..cfb29038c6 100644 --- a/src/Umbraco.Core/PublishedModelFactoryExtensions.cs +++ b/src/Umbraco.Core/PublishedModelFactoryExtensions.cs @@ -50,14 +50,17 @@ namespace Umbraco.Core { lock (liveFactory.SyncRoot) { - // TODO: Fix this in 8.3! - We need to change the ILivePublishedModelFactory interface to have a Reset method and then when we have an embedded MB - // version we will publicize the ResetModels (and change the name to Reset). - // For now, this will suffice and we'll use reflection, there should be no other implementation of ILivePublishedModelFactory. - // Calling ResetModels resets the MB flag so that the next time EnsureModels is called (which is called when nucache lazily calls CreateModel) it will - // trigger the recompiling of pure live models. - var resetMethod = liveFactory.GetType().GetMethod("ResetModels", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); - if (resetMethod != null) - resetMethod.Invoke(liveFactory, null); + if (liveFactory is ILivePublishedModelFactory2 liveFactory2) + { + liveFactory2.Reset(); + } + else + { + // This is purely here for backwards compat and to avoid breaking changes but this code will probably never get executed + var resetMethod = liveFactory.GetType().GetMethod("ResetModels", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); + if (resetMethod != null) + resetMethod.Invoke(liveFactory, null); + } action(); } diff --git a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs index 8e8a19c729..b642f93bc9 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs @@ -21,7 +21,7 @@ using File = System.IO.File; namespace Umbraco.ModelsBuilder.Embedded { - internal class PureLiveModelFactory : ILivePublishedModelFactory, IRegisteredObject + internal class PureLiveModelFactory : ILivePublishedModelFactory2, IRegisteredObject { private Assembly _modelsAssembly; private Infos _infos = new Infos { ModelInfos = null, ModelTypeMap = new Dictionary() }; @@ -134,6 +134,13 @@ namespace Umbraco.ModelsBuilder.Embedded return ctor(); } + /// + public void Reset() + { + if (_config.Enable) + ResetModels(); + } + #endregion #region Compilation