using System; using System.Collections.Generic; namespace ShiroginSDK.Runtime.Services.Base { /// /// Simple service locator for ShiroginSDK. /// Provides global access to registered service instances. /// public static class ServiceLocator { private static readonly Dictionary _services = new(); public static void Register(T service) where T : class { var type = typeof(T); if (_services.ContainsKey(type)) _services[type] = service; else _services.Add(type, service); } public static T Get() where T : class { if (_services.TryGetValue(typeof(T), out var service)) return service as T; throw new Exception($"[ShiroginSDK] Service not found: {typeof(T).Name}"); } public static bool TryGet(out T service) where T : class { if (_services.TryGetValue(typeof(T), out var obj)) { service = obj as T; return true; } service = null; return false; } public static void Clear() { _services.Clear(); } } }