using Microsoft.AspNetCore.Components; namespace TIAMWebApp.Shared.Application.Interfaces { public abstract class ComponentUpdateServiceBase : IComponentUpdateService { protected Dictionary ComponentsByType = []; public virtual void CallRequestRefreshAll() { foreach (var component in ComponentsByType.Values) component.CallRequestRefresh(); } public void CallRequestRefresh() where T : class, IComponent { if (ComponentsByType.TryGetValue(typeof(T), out var componentUpdateItem)) componentUpdateItem.CallRequestRefresh(); } public IComponentUpdateItem GetOrAddComponent() where T : class, IComponent { var componentType = typeof(T); if (ComponentsByType.TryGetValue(componentType, out var componentUpdateItem)) return componentUpdateItem; componentUpdateItem = new ComponentUpdateItem(); ComponentsByType.Add(componentType, componentUpdateItem); return componentUpdateItem; } } public class ComponentUpdateItem : IComponentUpdateItem { public event Action? RefreshRequested; public virtual void CallRequestRefresh() { RefreshRequested?.Invoke(); } } public interface IComponentUpdateItem { event Action? RefreshRequested; void CallRequestRefresh(); } public interface IComponentUpdateService { void CallRequestRefreshAll(); void CallRequestRefresh() where T : class, IComponent; IComponentUpdateItem GetOrAddComponent() where T : class, IComponent; } }