using System; using System.Collections.Concurrent; namespace SHJX.Service.Common.Utils { public static class Messager where T : class { private static readonly ConcurrentDictionary> Actions = new(); /// /// 注册消息 /// public static void Register(string name, Action action) { if (!Actions.ContainsKey(name)) { Actions.TryAdd(name, action); } Actions[name] = action; } /// /// 消息发送 /// public static void Send(string name, T t = null) { if (Actions.TryGetValue(name, out Action service)) { service?.Invoke(t); } } } }