35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using TIAMWebApp.Shared.Application.Interfaces;
|
|
|
|
namespace TIAMWebApp.Shared.Application.Services;
|
|
|
|
public abstract class ComponentUpdateServiceBase : IComponentUpdateService
|
|
{
|
|
protected Dictionary<Type, IComponentUpdateItem> ComponentsByType = [];
|
|
|
|
public virtual void CallRequestRefreshAll()
|
|
{
|
|
foreach (var component in ComponentsByType.Values)
|
|
component.CallRequestRefresh();
|
|
}
|
|
|
|
public void CallRequestRefresh<T>() where T : class, IComponent
|
|
{
|
|
if (ComponentsByType.TryGetValue(typeof(T), out var componentUpdateItem))
|
|
componentUpdateItem.CallRequestRefresh();
|
|
|
|
}
|
|
|
|
public IComponentUpdateItem GetOrAddComponent<T>() 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;
|
|
}
|
|
} |