using System; using System.Collections.Generic; using System.Linq; using umbraco.interfaces; namespace Umbraco.Core.ObjectResolution { /// /// A resolver to return all IApplicationEvents objects /// internal sealed class ApplicationEventsResolver : ManyObjectsResolverBase { private readonly LegacyStartupHandlerResolver _legacyResolver; /// /// Constructor /// /// internal ApplicationEventsResolver(IEnumerable applicationEventHandlers) : base(applicationEventHandlers) { //create the legacy resolver and only include the legacy types _legacyResolver = new LegacyStartupHandlerResolver( applicationEventHandlers.Where(x => !TypeHelper.IsTypeAssignableFrom(x))); } /// /// Override in order to only return types of IApplicationEventHandler and above, /// do not include the legacy types of IApplicationStartupHandler /// protected override IEnumerable InstanceTypes { get { return base.InstanceTypes.Where(TypeHelper.IsTypeAssignableFrom); } } /// /// Gets the implementations. /// public IEnumerable ApplicationEventHandlers { get { return Values; } } /// /// Create instances of all of the legacy startup handlers /// public void InstantiateLegacyStartupHandlers() { //this will instantiate them all var handlers = _legacyResolver.LegacyStartupHandlers; } protected override bool SupportsClear { get { return false; } } protected override bool SupportsInsert { get { return false; } } private class LegacyStartupHandlerResolver : ManyObjectsResolverBase { internal LegacyStartupHandlerResolver(IEnumerable legacyStartupHandlers) : base(legacyStartupHandlers) { } public IEnumerable LegacyStartupHandlers { get { return Values; } } } } }