diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs
index b1cac29d63..6af41ad0c2 100644
--- a/src/Umbraco.Core/CoreBootManager.cs
+++ b/src/Umbraco.Core/CoreBootManager.cs
@@ -114,15 +114,15 @@ namespace Umbraco.Core
if (_isStarted)
throw new InvalidOperationException("The boot manager has already been initialized");
- if (afterStartup != null)
- {
- afterStartup(ApplicationContext.Current);
- }
-
//call OnApplicationStarting of each application events handler
ApplicationEventsResolver.Current.ApplicationEventHandlers
.ForEach(x => x.OnApplicationStarting(UmbracoApplication, ApplicationContext));
+ if (afterStartup != null)
+ {
+ afterStartup(ApplicationContext.Current);
+ }
+
_isStarted = true;
return this;
@@ -144,15 +144,18 @@ namespace Umbraco.Core
//stop the timer and log the output
_timer.Dispose();
- if (afterComplete != null)
- {
- afterComplete(ApplicationContext.Current);
- }
-
//call OnApplicationStarting of each application events handler
ApplicationEventsResolver.Current.ApplicationEventHandlers
.ForEach(x => x.OnApplicationStarted(UmbracoApplication, ApplicationContext));
+ //Now, startup all of our legacy startup handler
+ ApplicationEventsResolver.Current.InstantiateLegacyStartupHanlders();
+
+ if (afterComplete != null)
+ {
+ afterComplete(ApplicationContext.Current);
+ }
+
_isComplete = true;
// we're ready to serve content!
diff --git a/src/Umbraco.Core/ObjectResolution/ApplicationEventsResolver.cs b/src/Umbraco.Core/ObjectResolution/ApplicationEventsResolver.cs
index fcfc1f3d55..ab5e31b2d3 100644
--- a/src/Umbraco.Core/ObjectResolution/ApplicationEventsResolver.cs
+++ b/src/Umbraco.Core/ObjectResolution/ApplicationEventsResolver.cs
@@ -8,27 +8,49 @@ namespace Umbraco.Core.ObjectResolution
///
/// A resolver to return all IApplicationEvents objects
///
- internal sealed class ApplicationEventsResolver : ManyObjectsResolverBase
+ 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.OfType(); }
+ get { return Values; }
}
+ ///
+ /// Create instances of all of the legacy startup handlers
+ ///
+ public void InstantiateLegacyStartupHanlders()
+ {
+ //this will instantiate them all
+ var handlers = _legacyResolver.LegacyStartupHandlers;
+ }
+
protected override bool SupportsClear
{
get { return false; }
@@ -39,5 +61,19 @@ namespace Umbraco.Core.ObjectResolution
get { return false; }
}
+ private class LegacyStartupHandlerResolver : ManyObjectsResolverBase
+ {
+ internal LegacyStartupHandlerResolver(IEnumerable legacyStartupHandlers)
+ : base(legacyStartupHandlers)
+ {
+
+ }
+
+ public IEnumerable LegacyStartupHandlers
+ {
+ get { return Values; }
+ }
+ }
+
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs b/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs
index a11c7c4b17..d792e4b2c0 100644
--- a/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs
+++ b/src/Umbraco.Tests/BootManagers/CoreBootManagerTests.cs
@@ -6,6 +6,7 @@ using System.Web;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.ObjectResolution;
+using umbraco.interfaces;
namespace Umbraco.Tests.BootManagers
{
@@ -53,12 +54,14 @@ namespace Umbraco.Tests.BootManagers
protected override void InitializeApplicationEventsResolver()
{
//create an empty resolver so we can add our own custom ones (don't type find)
- ApplicationEventsResolver.Current = new ApplicationEventsResolver(
- Enumerable.Empty())
+ ApplicationEventsResolver.Current = new ApplicationEventsResolver(new Type[]
+ {
+ typeof(LegacyStartupHandler),
+ typeof(TestApplicationEventHandler)
+ })
{
CanResolveBeforeFrozen = true
};
- ApplicationEventsResolver.Current.AddType();
}
protected override void InitializeResolvers()
@@ -67,6 +70,19 @@ namespace Umbraco.Tests.BootManagers
}
}
+ ///
+ /// Test legacy startup handler
+ ///
+ public class LegacyStartupHandler : IApplicationStartupHandler
+ {
+ public static bool Initialized = false;
+
+ public LegacyStartupHandler()
+ {
+ Initialized = true;
+ }
+ }
+
///
/// test event handler
///
@@ -102,5 +118,29 @@ namespace Umbraco.Tests.BootManagers
Assert.IsTrue(TestApplicationEventHandler.Started);
}
+ [Test]
+ public void Ensure_Legacy_Startup_Handlers_Not_Started_Until_Complete()
+ {
+ EventHandler starting = (sender, args) =>
+ {
+ Assert.IsTrue(TestApplicationEventHandler.Initialized);
+ Assert.IsTrue(TestApplicationEventHandler.Starting);
+ Assert.IsFalse(LegacyStartupHandler.Initialized);
+ };
+ EventHandler started = (sender, args) =>
+ {
+ Assert.IsTrue(TestApplicationEventHandler.Started);
+ Assert.IsTrue(LegacyStartupHandler.Initialized);
+ };
+ TestApp.ApplicationStarting += starting;
+ TestApp.ApplicationStarted += started;
+
+ _testApp.StartApplication(_testApp, new EventArgs());
+
+ TestApp.ApplicationStarting -= starting;
+ TestApp.ApplicationStarting -= started;
+
+ }
+
}
}