Fixes: #U4-1718
This commit is contained in:
@@ -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!
|
||||
|
||||
@@ -8,27 +8,49 @@ namespace Umbraco.Core.ObjectResolution
|
||||
/// <summary>
|
||||
/// A resolver to return all IApplicationEvents objects
|
||||
/// </summary>
|
||||
internal sealed class ApplicationEventsResolver : ManyObjectsResolverBase<ApplicationEventsResolver, IApplicationStartupHandler>
|
||||
internal sealed class ApplicationEventsResolver : ManyObjectsResolverBase<ApplicationEventsResolver, IApplicationEventHandler>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
private readonly LegacyStartupHandlerResolver _legacyResolver;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="applicationEventHandlers"></param>
|
||||
internal ApplicationEventsResolver(IEnumerable<Type> applicationEventHandlers)
|
||||
: base(applicationEventHandlers)
|
||||
{
|
||||
|
||||
//create the legacy resolver and only include the legacy types
|
||||
_legacyResolver = new LegacyStartupHandlerResolver(
|
||||
applicationEventHandlers.Where(x => !TypeHelper.IsTypeAssignableFrom<IApplicationEventHandler>(x)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Override in order to only return types of IApplicationEventHandler and above,
|
||||
/// do not include the legacy types of IApplicationStartupHandler
|
||||
/// </summary>
|
||||
protected override IEnumerable<Type> InstanceTypes
|
||||
{
|
||||
get { return base.InstanceTypes.Where(TypeHelper.IsTypeAssignableFrom<IApplicationEventHandler>); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IApplicationEventHandler"/> implementations.
|
||||
/// </summary>
|
||||
public IEnumerable<IApplicationEventHandler> ApplicationEventHandlers
|
||||
{
|
||||
get { return Values.OfType<IApplicationEventHandler>(); }
|
||||
get { return Values; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create instances of all of the legacy startup handlers
|
||||
/// </summary>
|
||||
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<ApplicationEventsResolver, IApplicationStartupHandler>
|
||||
{
|
||||
internal LegacyStartupHandlerResolver(IEnumerable<Type> legacyStartupHandlers)
|
||||
: base(legacyStartupHandlers)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<IApplicationStartupHandler> LegacyStartupHandlers
|
||||
{
|
||||
get { return Values; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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<Type>())
|
||||
ApplicationEventsResolver.Current = new ApplicationEventsResolver(new Type[]
|
||||
{
|
||||
typeof(LegacyStartupHandler),
|
||||
typeof(TestApplicationEventHandler)
|
||||
})
|
||||
{
|
||||
CanResolveBeforeFrozen = true
|
||||
};
|
||||
ApplicationEventsResolver.Current.AddType<TestApplicationEventHandler>();
|
||||
}
|
||||
|
||||
protected override void InitializeResolvers()
|
||||
@@ -67,6 +70,19 @@ namespace Umbraco.Tests.BootManagers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test legacy startup handler
|
||||
/// </summary>
|
||||
public class LegacyStartupHandler : IApplicationStartupHandler
|
||||
{
|
||||
public static bool Initialized = false;
|
||||
|
||||
public LegacyStartupHandler()
|
||||
{
|
||||
Initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// test event handler
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user