From 309bb3977fb50e73058b8ce2470fdf7dfcc2fab8 Mon Sep 17 00:00:00 2001 From: Georg von Kries Date: Fri, 14 Jun 2024 10:25:00 +0200 Subject: [PATCH 1/3] Adds a overload to RegisterBeforeDispose() to allow adding callbacks at the end of the list. --- .../Shell/Scope/ShellScope.cs | 16 ++++++++++++++-- .../Shell/Scope/ShellScopeExtensions.cs | 8 ++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs b/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs index cf2889fd8a7..cf7f23a2407 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs @@ -376,7 +376,19 @@ internal async Task ActivateShellInternalAsync() /// /// Registers a delegate to be invoked when 'BeforeDisposeAsync()' is called on this scope. /// - internal void BeforeDispose(Func callback) => (_beforeDispose ??= []).Insert(0, callback); + internal void BeforeDispose(Func callback, bool last) + { + var list = _beforeDispose ??= []; + + if (last) + { + list.Add(callback); + } + else + { + list.Insert(0, callback); + } + } /// /// Adds a Signal (if not already present) to be sent just after 'BeforeDisposeAsync()'. @@ -396,7 +408,7 @@ internal async Task ActivateShellInternalAsync() /// /// Registers a delegate to be invoked before the current shell scope will be disposed. /// - public static void RegisterBeforeDispose(Func callback) => Current?.BeforeDispose(callback); + public static void RegisterBeforeDispose(Func callback, bool last = false) => Current?.BeforeDispose(callback, last); /// /// Adds a Signal (if not already present) to be sent just before the current shell scope will be disposed. diff --git a/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs b/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs index 4c91df15f42..b21bd9cbcca 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs @@ -8,22 +8,22 @@ public static class ShellScopeExtensions /// /// Registers a delegate task to be invoked before this shell scope will be disposed. /// - public static ShellScope RegisterBeforeDispose(this ShellScope scope, Func callback) + public static ShellScope RegisterBeforeDispose(this ShellScope scope, Func callback, bool last = false) { - scope?.BeforeDispose(callback); + scope?.BeforeDispose(callback, last); return scope; } /// /// Registers a delegate action to be invoked before this shell scope will be disposed. /// - public static ShellScope RegisterBeforeDispose(this ShellScope scope, Action callback) + public static ShellScope RegisterBeforeDispose(this ShellScope scope, Action callback, bool last = false) { scope?.BeforeDispose(scope => { callback(scope); return Task.CompletedTask; - }); + }, last); return scope; } From e465b51d71231a4c205274bd55d6395c4fb2b2f9 Mon Sep 17 00:00:00 2001 From: Georg von Kries Date: Mon, 17 Jun 2024 12:56:01 +0200 Subject: [PATCH 2/3] Update src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs b/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs index b21bd9cbcca..a570ebd8663 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs @@ -11,6 +11,7 @@ public static class ShellScopeExtensions public static ShellScope RegisterBeforeDispose(this ShellScope scope, Func callback, bool last = false) { scope?.BeforeDispose(callback, last); + return scope; } From 92d75d6abe5ef2e0df80fa56f6d8892f8125d315 Mon Sep 17 00:00:00 2001 From: Georg von Kries Date: Mon, 17 Jun 2024 13:05:03 +0200 Subject: [PATCH 3/3] Added parameters documentation. --- .../OrchardCore.Abstractions/Shell/Scope/ShellScope.cs | 3 +++ .../Shell/Scope/ShellScopeExtensions.cs | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs b/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs index cf7f23a2407..1455015082a 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScope.cs @@ -376,6 +376,9 @@ internal async Task ActivateShellInternalAsync() /// /// Registers a delegate to be invoked when 'BeforeDisposeAsync()' is called on this scope. /// + /// The delegate to be invoked before disposal. This delegate takes a parameter and returns a . + /// A boolean value indicating whether the delegate should be invoked last. + /// If true, the delegate is added to the end of the invocation list; otherwise, it is added to the beginning. internal void BeforeDispose(Func callback, bool last) { var list = _beforeDispose ??= []; diff --git a/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs b/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs index a570ebd8663..a2625ebb192 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Shell/Scope/ShellScopeExtensions.cs @@ -8,6 +8,11 @@ public static class ShellScopeExtensions /// /// Registers a delegate task to be invoked before this shell scope will be disposed. /// + /// The instance on which to register the delegate. + /// The delegate task to be invoked before disposal. This delegate takes a parameter and returns a . + /// A boolean value indicating whether the delegate should be invoked last. + /// If true, the delegate is added to the end of the invocation list; otherwise, it is added to the beginning. The default value is false. + /// The instance for chaining further calls. public static ShellScope RegisterBeforeDispose(this ShellScope scope, Func callback, bool last = false) { scope?.BeforeDispose(callback, last); @@ -18,6 +23,11 @@ public static ShellScope RegisterBeforeDispose(this ShellScope scope, Func /// Registers a delegate action to be invoked before this shell scope will be disposed. /// + /// The instance on which to register the delegate. + /// The delegate action to be invoked before disposal. This delegate takes a parameter. + /// A boolean value indicating whether the delegate should be invoked last. + /// If true, the delegate is added to the end of the invocation list; otherwise, it is added to the beginning. The default value is false. + /// The instance for chaining further calls. public static ShellScope RegisterBeforeDispose(this ShellScope scope, Action callback, bool last = false) { scope?.BeforeDispose(scope =>