2012-07-26 07:52:13 -02:00
|
|
|
|
using System;
|
|
|
|
|
|
|
2012-08-10 13:18:13 +06:00
|
|
|
|
namespace Umbraco.Core.ObjectResolution
|
2012-07-26 07:52:13 -02:00
|
|
|
|
{
|
2012-07-27 05:52:01 +06:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A Resolver to return and set a Single registered object.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TResolved"></typeparam>
|
2012-08-01 22:06:15 +06:00
|
|
|
|
/// <typeparam name="TResolver"> </typeparam>
|
2012-07-27 05:52:01 +06:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// Used for 'singly' registered objects. An example is like the MVC Controller Factory, only one exists application wide and it can
|
|
|
|
|
|
/// be get/set.
|
|
|
|
|
|
/// </remarks>
|
2012-08-01 22:06:15 +06:00
|
|
|
|
internal abstract class SingleObjectResolverBase<TResolver, TResolved> : ResolverBase<TResolver>
|
2012-07-27 05:25:26 +06:00
|
|
|
|
where TResolved : class
|
2012-08-01 22:06:15 +06:00
|
|
|
|
where TResolver : class
|
2012-07-26 07:52:13 -02:00
|
|
|
|
{
|
|
|
|
|
|
TResolved _resolved;
|
2012-07-26 23:05:51 +06:00
|
|
|
|
readonly bool _canBeNull;
|
2012-07-26 07:52:13 -02:00
|
|
|
|
|
2012-07-30 22:52:59 +06:00
|
|
|
|
protected SingleObjectResolverBase()
|
2012-07-26 07:52:13 -02:00
|
|
|
|
: this(false)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
2012-07-30 22:52:59 +06:00
|
|
|
|
protected SingleObjectResolverBase(TResolved value)
|
2012-07-26 07:52:13 -02:00
|
|
|
|
: this(false)
|
|
|
|
|
|
{
|
|
|
|
|
|
_resolved = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-30 22:52:59 +06:00
|
|
|
|
protected SingleObjectResolverBase(bool canBeNull)
|
2012-07-26 07:52:13 -02:00
|
|
|
|
{
|
|
|
|
|
|
_canBeNull = canBeNull;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-30 22:52:59 +06:00
|
|
|
|
protected SingleObjectResolverBase(TResolved value, bool canBeNull)
|
2012-07-26 07:52:13 -02:00
|
|
|
|
{
|
|
|
|
|
|
_resolved = value;
|
|
|
|
|
|
_canBeNull = canBeNull;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-07-27 05:52:01 +06:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets/sets the value of the object
|
|
|
|
|
|
/// </summary>
|
2012-07-26 07:52:13 -02:00
|
|
|
|
protected TResolved Value
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _resolved;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_canBeNull && value == null)
|
|
|
|
|
|
throw new ArgumentNullException("value");
|
|
|
|
|
|
_resolved = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|