77
88namespace AIStudio . Dialogs . Settings ;
99
10- public abstract class SettingsDialogBase : ComponentBase
10+ public abstract class SettingsDialogBase : ComponentBase , IMessageBusReceiver , IDisposable
1111{
1212 [ CascadingParameter ]
1313 protected IMudDialogInstance MudDialog { get ; set ; } = null ! ;
@@ -30,11 +30,15 @@ public abstract class SettingsDialogBase : ComponentBase
3030 #region Overrides of ComponentBase
3131
3232 /// <inheritdoc />
33- protected override void OnInitialized ( )
33+ protected override async Task OnInitializedAsync ( )
3434 {
35+ // Register this component with the message bus:
36+ this . MessageBus . RegisterComponent ( this ) ;
37+ this . MessageBus . ApplyFilters ( this , [ ] , [ Event . CONFIGURATION_CHANGED ] ) ;
38+
3539 this . UpdateProviders ( ) ;
3640 this . UpdateEmbeddingProviders ( ) ;
37- base . OnInitialized ( ) ;
41+ await base . OnInitializedAsync ( ) ;
3842 }
3943
4044 #endregion
@@ -55,4 +59,36 @@ private void UpdateEmbeddingProviders()
5559 foreach ( var provider in this . SettingsManager . ConfigurationData . EmbeddingProviders )
5660 this . availableEmbeddingProviders . Add ( new ( provider . Name , provider . Id ) ) ;
5761 }
62+
63+ #region Implementation of IMessageBusReceiver
64+
65+ public string ComponentName => nameof ( Settings ) ;
66+
67+ public Task ProcessMessage < TMsg > ( ComponentBase ? sendingComponent , Event triggeredEvent , TMsg ? data )
68+ {
69+ switch ( triggeredEvent )
70+ {
71+ case Event . CONFIGURATION_CHANGED :
72+ this . StateHasChanged ( ) ;
73+ break ;
74+ }
75+
76+ return Task . CompletedTask ;
77+ }
78+
79+ public Task < TResult ? > ProcessMessageWithResult < TPayload , TResult > ( ComponentBase ? sendingComponent , Event triggeredEvent , TPayload ? data )
80+ {
81+ return Task . FromResult < TResult ? > ( default ) ;
82+ }
83+
84+ #endregion
85+
86+ #region Implementation of IDisposable
87+
88+ public void Dispose ( )
89+ {
90+ this . MessageBus . Unregister ( this ) ;
91+ }
92+
93+ #endregion
5894}
0 commit comments