From ed37b84b3b3825a88b4d3c65eafc0342cea71751 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 24 Nov 2016 11:20:01 +0100 Subject: [PATCH] makes public the WeightedPluginAttribute, uses this for resolving the startup handlers so they could be sorted, adds special event to allow modifying the startup handlers. --- .../ApplicationEventsEventArgs.cs | 15 +++++++ .../ApplicationEventsResolver.cs | 45 +++++++++++++++---- .../WeightedPluginAttribute.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 1 + 4 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 src/Umbraco.Core/ObjectResolution/ApplicationEventsEventArgs.cs diff --git a/src/Umbraco.Core/ObjectResolution/ApplicationEventsEventArgs.cs b/src/Umbraco.Core/ObjectResolution/ApplicationEventsEventArgs.cs new file mode 100644 index 0000000000..a459fc7268 --- /dev/null +++ b/src/Umbraco.Core/ObjectResolution/ApplicationEventsEventArgs.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace Umbraco.Core.ObjectResolution +{ + public class ApplicationEventsEventArgs : EventArgs + { + public List Handlers { get; private set; } + + public ApplicationEventsEventArgs(List handlers) + { + Handlers = handlers; + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/ObjectResolution/ApplicationEventsResolver.cs b/src/Umbraco.Core/ObjectResolution/ApplicationEventsResolver.cs index 78c8f483f2..be94d7a3b9 100644 --- a/src/Umbraco.Core/ObjectResolution/ApplicationEventsResolver.cs +++ b/src/Umbraco.Core/ObjectResolution/ApplicationEventsResolver.cs @@ -13,7 +13,7 @@ namespace Umbraco.Core.ObjectResolution /// /// This is disposable because after the app has started it should be disposed to release any memory being occupied by instances. /// - internal sealed class ApplicationEventsResolver : ManyObjectsResolverBase, IDisposable + public sealed class ApplicationEventsResolver : ManyObjectsResolverBase, IDisposable { private readonly LegacyStartupHandlerResolver _legacyResolver; @@ -30,7 +30,7 @@ namespace Umbraco.Core.ObjectResolution //create the legacy resolver and only include the legacy types _legacyResolver = new LegacyStartupHandlerResolver( serviceProvider, logger, - applicationEventHandlers.Where(x => !TypeHelper.IsTypeAssignableFrom(x))); + applicationEventHandlers.Where(x => TypeHelper.IsTypeAssignableFrom(x) == false)); } /// @@ -42,14 +42,34 @@ namespace Umbraco.Core.ObjectResolution get { return base.InstanceTypes.Where(TypeHelper.IsTypeAssignableFrom); } } - /// - /// Gets the implementations. - /// - public IEnumerable ApplicationEventHandlers + private List _orderedAndFiltered; + + /// + /// Gets the implementations. + /// + public IEnumerable ApplicationEventHandlers { - get { return Values; } + get + { + if (_orderedAndFiltered == null) + { + _orderedAndFiltered = GetSortedValues().ToList(); + + //raise event so the collection can be modified + OnCollectionResolved(new ApplicationEventsEventArgs(_orderedAndFiltered)); + } + return _orderedAndFiltered; + } } + public event EventHandler CollectionResolved; + + private void OnCollectionResolved(ApplicationEventsEventArgs e) + { + var handler = CollectionResolved; + if (handler != null) handler(this, e); + } + /// /// Create instances of all of the legacy startup handlers /// @@ -146,7 +166,14 @@ namespace Umbraco.Core.ObjectResolution { _legacyResolver.Dispose(); ResetCollections(); + _orderedAndFiltered.Clear(); + _orderedAndFiltered = null; + + //Clear event handlers + CollectionResolved = null; + } - - } + + + } } \ No newline at end of file diff --git a/src/Umbraco.Core/ObjectResolution/WeightedPluginAttribute.cs b/src/Umbraco.Core/ObjectResolution/WeightedPluginAttribute.cs index 323142bd4c..69c763ed50 100644 --- a/src/Umbraco.Core/ObjectResolution/WeightedPluginAttribute.cs +++ b/src/Umbraco.Core/ObjectResolution/WeightedPluginAttribute.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.ObjectResolution /// Indicates the relative weight of a resolved object type. /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] - internal class WeightedPluginAttribute : Attribute + public class WeightedPluginAttribute : Attribute { /// /// Initializes a new instance of the class with a weight. diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 7a4c4f2363..3c58503b57 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -415,6 +415,7 @@ +