Changed the ILookup resolution, now that DocumentRequest object contains everything to do the lookups

we don't have to create each ILookup per request, these can exist one  per application.
This commit is contained in:
shannon@ShandemVaio
2012-07-21 00:59:27 +06:00
parent 36e3857643
commit d9faea49ec
3 changed files with 54 additions and 64 deletions

View File

@@ -8,33 +8,49 @@ using umbraco.BusinessLogic.Utils;
namespace Umbraco.Web
{
/// <summary>
/// Extension methods for the PluginResolver
/// </summary>
public static class PluginResolverExtensions
{
/// Extension methods for the PluginResolver
/// </summary>
public static class PluginResolverExtensions
{
private static volatile IEnumerable<Type> _lookups;
private static readonly object Locker = new object();
private static volatile IEnumerable<ILookup> _lookups;
private static readonly object Locker = new object();
/// <summary>
/// Returns all available ILookup objects
/// </summary>
/// <param name="plugins"></param>
/// <returns></returns>
internal static IEnumerable<Type> ResolveLookups(this PluginResolver plugins)
{
if (_lookups == null)
{
lock(Locker)
{
if (_lookups == null)
{
_lookups = TypeFinder.FindClassesOfType<ILookup>();
}
}
}
return _lookups;
}
/// <summary>
/// Returns all available ILookup objects
/// </summary>
/// <param name="plugins"></param>
/// <returns></returns>
internal static IEnumerable<ILookup> ResolveLookups(this PluginResolver plugins)
{
if (_lookups == null)
{
lock (Locker)
{
if (_lookups == null)
{
var lookupTypes = TypeFinder.FindClassesOfType<ILookup>();
var lookups = new List<ILookup>();
foreach (var l in lookupTypes)
{
try
{
var typeInstance = Activator.CreateInstance(l) as ILookup;
lookups.Add(typeInstance);
}
catch (Exception ex)
{
//TODO: Need to fix logging so this doesn't bork if no SQL connection
//Log.Add(LogTypes.Error, -1, "Error loading ILookup: " + ex.ToString());
}
}
//set the global
_lookups = lookups;
}
}
}
return _lookups;
}
}
}
}