Obsoletes umbraco.cms.businesslogic.datatype.controls.Factory with new Umbraco.Core.DataTypesResolver

This commit is contained in:
shannon@ShandemVaio
2012-08-01 10:05:39 +06:00
parent a0a99e8f12
commit bee357ffdc
8 changed files with 169 additions and 120 deletions

View File

@@ -1,15 +1,15 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Umbraco.Core.Resolving;
using umbraco.interfaces;
namespace Umbraco.Core
{
internal sealed class CacheRefreshersResolver : ManyObjectResolverBase<ICacheRefresher>
/// <summary>
/// A resolver to return all ICacheRefresher objects
/// </summary>
internal sealed class CacheRefreshersResolver : LegacyTransientObjectsResolver<ICacheRefresher>
{
#region Singleton
@@ -28,29 +28,14 @@ namespace Umbraco.Core
/// <summary>
/// Constructor
/// </summary>
/// <param name="refreshers"></param>
/// <remarks>
/// We are creating Transient instances (new instances each time) because this is how the legacy code worked and
/// I don't want to muck anything up by changing them to application based instances.
/// TODO: However, it would make much more sense to do this and would speed up the application plus this would make the GetById method much easier.
/// </remarks>
/// <param name="refreshers"></param>
internal CacheRefreshersResolver(IEnumerable<Type> refreshers)
: base(true)
: base(refreshers)
{
foreach (var l in refreshers)
{
this.Add(l);
}
}
#endregion
/// <summary>
/// Maintains a list of Ids and their types when first call to CacheResolvers or GetById occurs, this is used
/// in order to return a single object by id without instantiating the entire type stack.
/// </summary>
private static ConcurrentDictionary<Guid, Type> _refreshers;
private readonly ReaderWriterLockSlim _lock= new ReaderWriterLockSlim();
/// <summary>
/// Gets the <see cref="ICacheRefresher"/> implementations.
/// </summary>
@@ -63,37 +48,9 @@ namespace Umbraco.Core
}
}
/// <summary>
/// Returns a new ICacheRefresher instance by id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public ICacheRefresher GetById(Guid id)
protected override Guid GetUniqueIdentifier(ICacheRefresher obj)
{
EnsureRefreshersList();
return !_refreshers.ContainsKey(id)
? null
: PluginTypeResolver.Current.CreateInstance<ICacheRefresher>(_refreshers[id]);
return obj.UniqueIdentifier;
}
/// <summary>
/// Populates the refreshers dictionary to allow us to instantiate a type by Id since the ICacheRefresher type doesn't contain any metadata
/// </summary>
private void EnsureRefreshersList()
{
using (var l = new UpgradeableReadLock(_lock))
{
if (_refreshers == null)
{
l.UpgradeToWriteLock();
_refreshers = new ConcurrentDictionary<Guid, Type>();
foreach(var v in Values)
{
_refreshers.TryAdd(v.UniqueIdentifier, v.GetType());
}
}
}
}
}
}