Fixes up ResolverBase and it's static lock object which isn't actually required because
our singleton is a getter/setter and field access is thread safe. Updated SingleResolverBase to ensure that TResolved is a class so the null check works properly.
This commit is contained in:
@@ -3,36 +3,13 @@ using System.Threading;
|
||||
|
||||
namespace Umbraco.Core.Resolving
|
||||
{
|
||||
internal abstract class ResolverBase<TResolver> where TResolver : class
|
||||
/// <summary>
|
||||
/// base class for resolvers which declare a singleton accessor
|
||||
/// </summary>
|
||||
/// <typeparam name="TResolver"></typeparam>
|
||||
internal abstract class ResolverBase<TResolver>
|
||||
where TResolver : class
|
||||
{
|
||||
static TResolver _resolver;
|
||||
|
||||
//TODO: This is not correct, this will be the same lock for all ResolverBase classes!!
|
||||
static readonly ReaderWriterLockSlim ResolversLock = new ReaderWriterLockSlim();
|
||||
|
||||
public static TResolver Current
|
||||
{
|
||||
get
|
||||
{
|
||||
using (new ReadLock(ResolversLock))
|
||||
{
|
||||
if (_resolver == null)
|
||||
throw new InvalidOperationException("Current has not been initialized. You must initialize Current before trying to read it.");
|
||||
return _resolver;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
using (new WriteLock(ResolversLock))
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("value");
|
||||
if (_resolver != null)
|
||||
throw new InvalidOperationException("Current has already been initialized. It is not possible to re-initialize Current once it has been initialized.");
|
||||
_resolver = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static TResolver Current { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
namespace Umbraco.Core.Resolving
|
||||
{
|
||||
internal abstract class SingleResolverBase<TResolver, TResolved> : ResolverBase<TResolver>
|
||||
where TResolver : class
|
||||
where TResolver : class
|
||||
where TResolved : class
|
||||
{
|
||||
TResolved _resolved;
|
||||
readonly bool _canBeNull;
|
||||
|
||||
Reference in New Issue
Block a user