2012-08-01 22:06:15 +06:00
|
|
|
|
using System;
|
|
|
|
|
|
|
2012-08-10 13:18:13 +06:00
|
|
|
|
namespace Umbraco.Core.ObjectResolution
|
2012-08-01 22:06:15 +06:00
|
|
|
|
{
|
2013-01-16 13:10:34 -01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Represents the status of objects resolution.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// <para>Objects resolution can be frozen ie nothing can change anymore.</para>
|
|
|
|
|
|
/// <para>Nothing in resolution is thread-safe, because everything should take place when the application is starting.</para>
|
|
|
|
|
|
/// </remarks>
|
2012-08-01 22:06:15 +06:00
|
|
|
|
internal class Resolution
|
|
|
|
|
|
{
|
2013-01-16 13:10:34 -01:00
|
|
|
|
// NOTE : must clarify freezing... SingleObjectResolverBase does not honor it...
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Occurs when resolution is frozen.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>Occurs only once, since resolution can be frozen only once.</remarks>
|
2012-08-01 22:06:15 +06:00
|
|
|
|
public static event EventHandler Frozen;
|
|
|
|
|
|
|
2012-08-01 22:46:13 +06:00
|
|
|
|
/// <summary>
|
2013-01-16 13:10:34 -01:00
|
|
|
|
/// Gets or sets a value indicating whether resolution of objects is frozen.
|
2012-08-01 22:46:13 +06:00
|
|
|
|
/// </summary>
|
2013-01-16 13:10:34 -01:00
|
|
|
|
/// <remarks>The internal setter is to be used in unit tests.</remarks>
|
2012-08-01 22:46:13 +06:00
|
|
|
|
public static bool IsFrozen { get; internal set; }
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2013-01-16 13:10:34 -01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Ensures that resolution is not frozen, else throws.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <exception cref="InvalidOperationException">resolution is frozen.</exception>
|
2012-08-01 22:06:15 +06:00
|
|
|
|
public static void EnsureNotFrozen()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Resolution.IsFrozen)
|
|
|
|
|
|
throw new InvalidOperationException("Resolution is frozen. It is not possible to modify resolvers once resolution is frozen.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-16 13:10:34 -01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Freezes resolution.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <exception cref="InvalidOperationException">resolution is already frozen.</exception>
|
2012-08-01 22:06:15 +06:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|