using System; using System.Collections.Generic; using UnityEngine; namespace Code.DI { public class DIContainer : MonoBehaviour { private readonly Dictionary _services = new(); private void Awake() { DontDestroyOnLoad(gameObject); } public void Register(T service) { var type = typeof(T); if (!_services.TryAdd(type, service)) { Debug.LogWarning($"Service {type} is already registered."); } } public T Resolve() { var type = typeof(T); if (_services.TryGetValue(type, out var service)) { return (T)service; } throw new Exception($"Service {type} not found."); } } }