#nullable enable using System; using System.Collections.Generic; namespace ShrinkModFramework; public sealed class ShrinkModContext { private readonly Dictionary _services = new(); public ShrinkModContext(string modDirectory) => ModDirectory = modDirectory ?? throw new ArgumentNullException(nameof(modDirectory)); public string ModDirectory { get; } public void RegisterService(T service) where T : class => _services[typeof(T)] = service ?? throw new ArgumentNullException(nameof(service)); public bool TryGetService(out T? service) where T : class { service = _services.TryGetValue(typeof(T), out var value) ? value as T : null; return service != null; } public T GetRequiredService() where T : class => TryGetService(out var value) ? value! : throw new InvalidOperationException($"Service is not registered: {typeof(T).FullName}"); } public interface IShrinkModUnload { void OnUnload(ShrinkModContext context); }