to all be lazy resolvers as they are not needed instantly on app startup (not needed by the front-end) This will make app startup a lot quicker. Fixes ActionsResolver to not use the PluginManager to resolve the types when it is instantiating them since these are passed in the ctor. Updates all unit tests to use lazy delegate for these resolvers and they are all passing.
59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using Umbraco.Core.ObjectResolution;
|
|
using umbraco.interfaces;
|
|
|
|
namespace Umbraco.Core
|
|
{
|
|
/// <summary>
|
|
/// A resolver to return all IAction objects
|
|
/// </summary>
|
|
internal sealed class ActionsResolver : LazyManyObjectsResolverBase<ActionsResolver, IAction>
|
|
{
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="packageActions"></param>
|
|
internal ActionsResolver(Func<IEnumerable<Type>> packageActions)
|
|
: base(packageActions)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the <see cref="IPackageAction"/> implementations.
|
|
/// </summary>
|
|
public IEnumerable<IAction> Actions
|
|
{
|
|
get
|
|
{
|
|
return Values;
|
|
}
|
|
}
|
|
|
|
protected override IEnumerable<IAction> CreateInstances()
|
|
{
|
|
var actions = new List<IAction>();
|
|
var foundIActions = InstanceTypes;
|
|
foreach (var type in foundIActions)
|
|
{
|
|
IAction typeInstance;
|
|
var instance = type.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static);
|
|
//if the singletone initializer is not found, try simply creating an instance of the IAction if it supports public constructors
|
|
if (instance == null)
|
|
typeInstance = PluginManager.Current.CreateInstance<IAction>(type);
|
|
else
|
|
typeInstance = instance.GetValue(null, null) as IAction;
|
|
|
|
if (typeInstance != null)
|
|
{
|
|
actions.Add(typeInstance);
|
|
}
|
|
}
|
|
return actions;
|
|
}
|
|
|
|
}
|
|
} |