Change Notifications
Services that own mutable application data can expose an OnDataChanged callback for in-process UI refresh notifications. The service should be registered with a lifetime that matches the intended audience of the notification. Singleton services notify all Blazor circuits and components; scoped or transient services notify only consumers sharing that service instance.
Raise the callback only after a successful mutation. Read operations should not raise it, and failed operations should not raise it. Existing services use this pattern for container, application, job, document, session, skill, and ontology data changes.
A Razor component that needs to react should subscribe during initialization and unsubscribe during disposal. The callback must restore the current user's language before reloading data, then marshal UI work through InvokeAsync:
protected override void OnInitialized() {
DataService.OnDataChanged += OnDataChanged;
}
private async void OnDataChanged() {
CultureService.CheckAndSetThreadLanguage(HttpParameters);
await InvokeAsync(async () => {
await ReloadData();
StateHasChanged();
});
}
public void Dispose() {
#pragma warning disable CS8601 // Possible null reference assignment
DataService.OnDataChanged -= OnDataChanged;
#pragma warning restore CS8601 // Possible null reference assignment
}
The callback is an in-process server notification. It does not detect changes made by a separate process unless that process calls the service in the same application instance or another notification mechanism is added. Components must reload their own data; raising the callback alone only signals that a refresh may be needed.