using System; using Umbraco.Core.Models.PublishedContent; namespace Umbraco.Core { /// /// Provides extension methods for . /// public static class PublishedModelFactoryExtensions { /// /// Executes an action with a safe live factory/ /// /// /// If the factory is a live factory, ensures it is refreshed and locked while executing the action. /// public static void WithSafeLiveFactory(this IPublishedModelFactory factory, Action action) { if (factory is ILivePublishedModelFactory liveFactory) { lock (liveFactory.SyncRoot) { liveFactory.Refresh(); action(); } } else { action(); } } } }