// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Cms.Core.Models.PublishedContent;
namespace Umbraco.Extensions;
///
/// Provides extension methods for .
///
public static class PublishedModelFactoryExtensions
{
///
/// Returns true if the current is an implementation of
/// and is enabled
///
public static bool IsLiveFactoryEnabled(this IPublishedModelFactory factory)
{
if (factory is IAutoPublishedModelFactory liveFactory)
{
return liveFactory.Enabled;
}
// if it's not ILivePublishedModelFactory we know we're not using a live factory
return false;
}
///
/// Sets a flag to reset the ModelsBuilder models if the is
///
///
///
/// This does not recompile the InMemory models, only sets a flag to tell models builder to recompile when they are
/// requested.
///
internal static void WithSafeLiveFactoryReset(this IPublishedModelFactory factory, Action action)
{
if (factory is IAutoPublishedModelFactory liveFactory)
{
lock (liveFactory.SyncRoot)
{
liveFactory.Reset();
action();
}
}
else
{
action();
}
}
}