Files
Umbraco-CMS/src/Umbraco.Core/ActionsResolver.cs
Shannon Deminick 82c2560822 Ensures all resolvers are sealed. Changes CacheRefreshersResolver, DataTypesResolver, MacroFieldEditorsResolver, PackageActionsResolver, ActionsResolver
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.
2013-01-23 18:40:40 +03:00

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;
}
}
}