Skip to content

Commit 02790ab

Browse files
committed
Added IMessenger.Cleanup API (to help with extensibility)
1 parent dea8b89 commit 02790ab

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Microsoft.Toolkit.Mvvm/Messaging/IMessenger.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ TMessage Send<TMessage, TToken>(TMessage message, TToken token)
9494
where TMessage : class
9595
where TToken : IEquatable<TToken>;
9696

97+
/// <summary>
98+
/// Performs a cleanup on the current messenger.
99+
/// Invoking this method does not unregister any of the currently registered
100+
/// recipient, and it can be used to perform cleanup operations such as
101+
/// trimming the internal data structures of a messenger implementation.
102+
/// </summary>
103+
void Cleanup();
104+
97105
/// <summary>
98106
/// Resets the <see cref="IMessenger"/> instance and unregisters all the existing recipients.
99107
/// </summary>

Microsoft.Toolkit.Mvvm/Messaging/Messenger.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,16 @@ public unsafe TMessage Send<TMessage, TToken>(TMessage message, TToken token)
480480
return message;
481481
}
482482

483+
/// <inheritdoc/>
484+
void IMessenger.Cleanup()
485+
{
486+
// The current implementation doesn't require any kind of cleanup operation, as
487+
// all the internal data structures are already kept in sync whenever a recipient
488+
// is added or removed. This method is implemented through an explicit interface
489+
// implementation so that developers using this type directly will not see it in
490+
// the API surface (as it wouldn't be useful anyway, since it's a no-op here).
491+
}
492+
483493
/// <inheritdoc/>
484494
public void Reset()
485495
{

0 commit comments

Comments
 (0)