From a95fbff5977f46c7774dbae5b9a07ec423829442 Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 23 Jan 2013 14:08:13 -0100 Subject: [PATCH] Core.ObjectsResolution - create temp. dirty access to resolution for legacy code --- .../ObjectResolution/Resolution.cs | 35 +++++++++++++++++++ src/umbraco.cms/Actions/Action.cs | 18 +++++----- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Core/ObjectResolution/Resolution.cs b/src/Umbraco.Core/ObjectResolution/Resolution.cs index 6933ea6d6a..d9e5977e4a 100644 --- a/src/Umbraco.Core/ObjectResolution/Resolution.cs +++ b/src/Umbraco.Core/ObjectResolution/Resolution.cs @@ -49,6 +49,41 @@ namespace Umbraco.Core.ObjectResolution } } + /// + /// Returns a disposable object that reprents dirty access to temporarily unfrozen resolution configuration. + /// + /// + /// Should not be used. + /// Should be used in a using(Resolution.DirtyBackdoorToConfiguration) { ... } mode. + /// Because we just lift the frozen state, and we don't actually re-freeze, the Frozen event does not trigger. + /// + internal static IDisposable DirtyBackdoorToConfiguration + { + get { return new DirtyBackdoor(); } + } + + // keep the class here because it needs write-access to Resolution.IsFrozen + private class DirtyBackdoor : IDisposable + { + private static readonly System.Threading.ReaderWriterLockSlim _dirtyLock = new ReaderWriterLockSlim(); + + private IDisposable _lock; + private bool _frozen; + + public DirtyBackdoor() + { + _lock = new WriteLock(_dirtyLock); + _frozen = Resolution.IsFrozen; + Resolution.IsFrozen = false; + } + + public void Dispose() + { + Resolution.IsFrozen = _frozen; + _lock.Dispose(); + } + } + /// /// Freezes resolution. /// diff --git a/src/umbraco.cms/Actions/Action.cs b/src/umbraco.cms/Actions/Action.cs index 24022721c0..95c2d45c2a 100644 --- a/src/umbraco.cms/Actions/Action.cs +++ b/src/umbraco.cms/Actions/Action.cs @@ -53,16 +53,18 @@ namespace umbraco.BusinessLogic.Actions { lock (Lock) { + using (Umbraco.Core.ObjectResolution.Resolution.DirtyBackdoorToConfiguration) + { + //TODO: Based on the above, this is a big hack as types should all be cleared on package install! + ActionsResolver.Reset(); + ActionHandlers.Clear(); - //TODO: Based on the above, this is a big hack as types should all be cleared on package install! - ActionsResolver.Reset(); - ActionHandlers.Clear(); + //TODO: Based on the above, this is a big hack as types should all be cleared on package install! + ActionsResolver.Current = new ActionsResolver( + () => TypeFinder.FindClassesOfType(PluginManager.Current.AssembliesToScan)); - //TODO: Based on the above, this is a big hack as types should all be cleared on package install! - ActionsResolver.Current = new ActionsResolver( - () => TypeFinder.FindClassesOfType(PluginManager.Current.AssembliesToScan)); - - RegisterIActionHandlers(); + RegisterIActionHandlers(); + } } }