using System; using System.Collections.Generic; namespace CoreBluetooth { internal class ServiceLocator { public static ServiceLocator Instance { get; private set; } = new ServiceLocator(); readonly Dictionary container = new Dictionary(); public void Register(T obj) where T : class { container[typeof(T)] = obj; } public bool Unregister() where T : class { return container.Remove(typeof(T)); } public T Resolve() where T : class { Type targetType = typeof(T); if (container.TryGetValue(targetType, out object obj)) { return obj as T; } return null; } } }