You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently ConfigurationManager uses an event pattern so that classes that want to know if the config was updated (or been applied) can update their state. This lets apps update in-real-time whenever config changes.
However, this pattern means classes like LineCanvas have to subscribe to an event:
And THIS means they also have to implement IDisposable to correctly unsubscribe. This is what led to a big memory leak reported in #2870. IMO, if the disposable pattern can be avoided, it should be as it relies on developers remembering to do things.
I propose that in addition to having these events classes can implement an ISupportConfigChanges interface:
/// <summary>/// <para>/// Classes should implement this interface on any class that should be notified when the configuration changes./// This is an alternative to using the <see cref="ConfigurationManager.Updated"/> and/// <see cref="ConfigurationManager.Applied"/> events./// <para>/// When the configuration has changed, the <see cref="ConfigurationManager"/> will call the <see cref="OnUpdated"/>/// method. When the configuration is being applied, the <see cref="OnApplied"/> method will be called./// /// </para>/// </summary>publicinterfaceISupportConfigChanges{/// <summary>/// Called when the configuration has been updated./// </summary>publicvoidOnUpdated();/// <summary>/// Called when the configuration is being applied./// </summary>publicvoidOnApplied();}
ConfigurationManager.OnApplied() currently looks like this:
/// <summary>/// Called when an updated configuration has been applied to the /// application. Fires the <see cref="Applied"/> event./// </summary>publicstaticvoidOnApplied(){Debug.WriteLine($"ConfigurationManager.OnApplied()");Applied?.Invoke(null,newConfigurationManagerEventArgs());}
We'll use reflection after the call to Applied?.Invoke() to find all instances of classes implementing ISupportConfigChanges and call the OnApplied() method on them.
I may be missing a better pattern for this, so i'd love to hear from others on this concept.
The text was updated successfully, but these errors were encountered:
Currently
ConfigurationManager
uses an event pattern so that classes that want to know if the config was updated (or been applied) can update their state. This lets apps update in-real-time whenever config changes.However, this pattern means classes like
LineCanvas
have to subscribe to an event:And THIS means they also have to implement
IDisposable
to correctly unsubscribe. This is what led to a big memory leak reported in #2870. IMO, if the disposable pattern can be avoided, it should be as it relies on developers remembering to do things.I propose that in addition to having these events classes can implement an
ISupportConfigChanges
interface:ConfigurationManager.OnApplied()
currently looks like this:We'll use reflection after the call to
Applied?.Invoke()
to find all instances of classes implementingISupportConfigChanges
and call theOnApplied()
method on them.I may be missing a better pattern for this, so i'd love to hear from others on this concept.
The text was updated successfully, but these errors were encountered: