using System; using System.Collections.Generic; namespace Notes.ViewModels; public sealed class Services:IServices { private readonly Dictionary map = new Dictionary(); public void Register(T t) { this.map.Add(typeof(T), t); } public T? Get() { this.map.TryGetValue(typeof(T), out var t); return (T?)t; } public T GetSafeAs() { T? foo = this.Get(); if (foo is { } t) return t; throw new InvalidOperationException($"Not find type '{typeof(T)}'"); } }