From d1aac3964c1b59cb75a0613daaab7d09d75ea3b4 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 18 Jul 2023 12:57:09 +0200 Subject: [PATCH] Restored order of operations on scope dispose to that used in Umbraco 11 before refactor into Scope inheriting CoreScope. (#14573) --- src/Umbraco.Core/Scoping/CoreScope.cs | 4 ++-- src/Umbraco.Infrastructure/Scoping/Scope.cs | 23 ++++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Core/Scoping/CoreScope.cs b/src/Umbraco.Core/Scoping/CoreScope.cs index a05b44f4a7..7fe6c400fb 100644 --- a/src/Umbraco.Core/Scoping/CoreScope.cs +++ b/src/Umbraco.Core/Scoping/CoreScope.cs @@ -231,7 +231,7 @@ public class CoreScope : ICoreScope } } - private void HandleScopedFileSystems() + protected void HandleScopedFileSystems() { if (_shouldScopeFileSystems == true) { @@ -250,7 +250,7 @@ public class CoreScope : ICoreScope _parentScope = coreScope; } - private void HandleScopedNotifications() => _notificationPublisher?.ScopeExit(Completed.HasValue && Completed.Value); + protected void HandleScopedNotifications() => _notificationPublisher?.ScopeExit(Completed.HasValue && Completed.Value); private void EnsureNotDisposed() { diff --git a/src/Umbraco.Infrastructure/Scoping/Scope.cs b/src/Umbraco.Infrastructure/Scoping/Scope.cs index 295c92a6d6..4455b01df3 100644 --- a/src/Umbraco.Infrastructure/Scoping/Scope.cs +++ b/src/Umbraco.Infrastructure/Scoping/Scope.cs @@ -357,7 +357,7 @@ namespace Umbraco.Cms.Infrastructure.Scoping } } - public void Dispose() + public override void Dispose() { EnsureNotDisposed(); @@ -402,16 +402,21 @@ namespace Umbraco.Cms.Infrastructure.Scoping Completed = true; } - if (ParentScope != null) - { - ParentScope.ChildCompleted(Completed); - } - else + // CoreScope.Dispose will handle file systems and notifications, as well as notifying any parent scope of the child scope's completion. + // In this overridden class, we re-use that functionality and also handle scope context (including enlisted actions) and detached scopes. + // We retain order of events behaviour from Umbraco 11: + // - handle file systems (in CoreScope) + // - handle scoped notifications (in CoreScope) + // - handle scope context (in Scope) + // - handle detatched scopes (in Scope) + if (ParentScope is null) { DisposeLastScope(); } - - base.Dispose(); + else + { + ParentScope.ChildCompleted(Completed); + } _disposed = true; } @@ -559,6 +564,8 @@ namespace Umbraco.Cms.Infrastructure.Scoping } TryFinally( + HandleScopedFileSystems, + HandleScopedNotifications, HandleScopeContext, HandleDetachedScopes); }