using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Umbraco.Core.ObjectResolution; using umbraco.interfaces; namespace Umbraco.Core { /// /// A resolver to return all IAction objects /// internal sealed class ActionsResolver : LazyManyObjectsResolverBase { /// /// Constructor /// /// internal ActionsResolver(Func> packageActions) : base(packageActions) { } /// /// Gets the implementations. /// public IEnumerable Actions { get { return Values; } } /// /// Gets an Action if it exists. /// /// /// internal IAction GetAction() where T : IAction { return Actions.SingleOrDefault(x => x.GetType() == typeof (T)); } protected override IEnumerable CreateInstances() { var actions = new List(); 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(type); else typeInstance = instance.GetValue(null, null) as IAction; if (typeInstance != null) { actions.Add(typeInstance); } } return actions; } } }