using System;
namespace Umbraco.Core.ObjectResolution
{
///
/// Represents the status of objects resolution.
///
///
/// Objects resolution can be frozen ie nothing can change anymore.
/// Nothing in resolution is thread-safe, because everything should take place when the application is starting.
///
internal class Resolution
{
// NOTE : must clarify freezing... SingleObjectResolverBase does not honor it...
///
/// Occurs when resolution is frozen.
///
/// Occurs only once, since resolution can be frozen only once.
public static event EventHandler Frozen;
///
/// Gets or sets a value indicating whether resolution of objects is frozen.
///
/// The internal setter is to be used in unit tests.
public static bool IsFrozen { get; internal set; }
///
/// Ensures that resolution is not frozen, else throws.
///
/// resolution is frozen.
public static void EnsureNotFrozen()
{
if (Resolution.IsFrozen)
throw new InvalidOperationException("Resolution is frozen. It is not possible to modify resolvers once resolution is frozen.");
}
///
/// Freezes resolution.
///
/// resolution is already frozen.
public static void Freeze()
{
if (Resolution.IsFrozen)
throw new InvalidOperationException("Resolution is frozen. It is not possible to freeze it again.");
IsFrozen = true;
if (Frozen != null)
Frozen(null, null);
}
}
}