Had to remove the Resolution freezing idea because we are lazily instantiating the singleton instances, otherwise
we have to instantiate them all on startup which means that all type searching happens on startup and not lazily which is bad for performance. I don't think its a big deal that we're not freezing these objects, MVC doesn't freeze its singletons and nobody seems to have a problem with it, people will just know not to modify these items after startup.
This commit is contained in:
@@ -90,11 +90,7 @@ namespace Umbraco.Core.Resolving
|
||||
protected IEnumerable<TResolved> Values
|
||||
{
|
||||
get
|
||||
{
|
||||
//we should not allow the returning/creating of objects if resolution is not yet frozen!
|
||||
if (Resolution.IsFrozen)
|
||||
throw new InvalidOperationException("Resolution is not frozen. It is not possible to instantiate and returng objects until resolution is frozen.");
|
||||
|
||||
{
|
||||
switch (LifetimeScope)
|
||||
{
|
||||
case ObjectLifetimeScope.HttpRequest:
|
||||
@@ -137,8 +133,7 @@ namespace Umbraco.Core.Resolving
|
||||
/// </summary>
|
||||
/// <param name="value">The type to remove.</param>
|
||||
public void Remove(Type value)
|
||||
{
|
||||
Resolution.EnsureNotFrozen();
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
using (new WriteLock(_lock))
|
||||
{
|
||||
@@ -161,7 +156,6 @@ namespace Umbraco.Core.Resolving
|
||||
/// <param name="value">The object to be added.</param>
|
||||
public void Add(Type value)
|
||||
{
|
||||
Resolution.EnsureNotFrozen();
|
||||
EnsureCorrectType(value);
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
@@ -189,7 +183,6 @@ namespace Umbraco.Core.Resolving
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
Resolution.EnsureNotFrozen();
|
||||
using (new WriteLock(_lock))
|
||||
{
|
||||
InstanceTypes.Clear();
|
||||
@@ -203,7 +196,6 @@ namespace Umbraco.Core.Resolving
|
||||
/// <param name="value">The object to insert.</param>
|
||||
public void Insert(int index, Type value)
|
||||
{
|
||||
Resolution.EnsureNotFrozen();
|
||||
EnsureCorrectType(value);
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Umbraco.Core.Resolving
|
||||
{
|
||||
// notes: nothing in Resolving is thread-safe because everything should happen when the app is starting
|
||||
|
||||
internal class Resolution
|
||||
{
|
||||
public static event EventHandler Frozen;
|
||||
|
||||
public static bool IsFrozen { get; private set; }
|
||||
|
||||
public static void EnsureNotFrozen()
|
||||
{
|
||||
if (Resolution.IsFrozen)
|
||||
throw new InvalidOperationException("Resolution is frozen. It is not possible to modify resolvers once resolution is frozen.");
|
||||
}
|
||||
|
||||
public static void Freeze()
|
||||
{
|
||||
if (Resolution.IsFrozen)
|
||||
throw new InvalidOperationException("Resolution is frozen. It is not possible to freeze it again.");
|
||||
|
||||
IsFrozen = true;
|
||||
if (Frozen != null)
|
||||
Frozen(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,6 @@ namespace Umbraco.Core.Resolving
|
||||
|
||||
set
|
||||
{
|
||||
Resolution.EnsureNotFrozen();
|
||||
|
||||
if (!_canBeNull && value == null)
|
||||
throw new ArgumentNullException("value");
|
||||
_resolved = value;
|
||||
|
||||
@@ -72,7 +72,6 @@
|
||||
<Compile Include="RazorDataTypeModelStaticMappingItem.cs" />
|
||||
<Compile Include="Resolving\ManyObjectResolverBase.cs" />
|
||||
<Compile Include="Resolving\ObjectLifetimeScope.cs" />
|
||||
<Compile Include="Resolving\Resolution.cs" />
|
||||
<Compile Include="Resolving\SingleObjectResolverBase.cs" />
|
||||
<Compile Include="TypeExtensions.cs" />
|
||||
<Compile Include="ReadLock.cs" />
|
||||
|
||||
@@ -17,8 +17,6 @@ namespace Umbraco.Web
|
||||
{
|
||||
public static event EventHandler ApplicationStarting;
|
||||
|
||||
public static event EventHandler ApplicationStarted;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the Umbraco application
|
||||
/// </summary>
|
||||
@@ -37,18 +35,13 @@ namespace Umbraco.Web
|
||||
//create the ApplicationContext
|
||||
ApplicationContext.Current = new ApplicationContext()
|
||||
{
|
||||
IsReady = true // fixme
|
||||
IsReady = true // fixme, do we need this?
|
||||
};
|
||||
|
||||
//find and initialize the application startup handlers
|
||||
ApplicationStartupHandler.RegisterHandlers();
|
||||
|
||||
OnApplicationStarting(sender, e);
|
||||
|
||||
//all resolvers are now frozen and cannot be modified
|
||||
Umbraco.Core.Resolving.Resolution.Freeze();
|
||||
|
||||
OnApplicationStarted(sender, e);
|
||||
OnApplicationStarting(sender, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,18 +55,7 @@ namespace Umbraco.Web
|
||||
if (ApplicationStarting != null)
|
||||
ApplicationStarting(sender, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Developers can override this method to do anything they need to do once the application startup routine is completed.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected virtual void OnApplicationStarted(object sender, EventArgs e)
|
||||
{
|
||||
if (ApplicationStarted != null)
|
||||
ApplicationStarted(sender, e);
|
||||
}
|
||||
|
||||
|
||||
protected virtual void Application_Error(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user