A small internal class implementing ICommandServices that holds a read-only map of service types to instances and returns services by generic type. It copies the provided dictionary into an internal dictionary and exposes an Empty singleton.
namespace SboxSuperuser.Engine.Commands;
internal sealed class CommandCapabilities : ICommandServices
{
private readonly IReadOnlyDictionary<Type, object> _values;
internal static CommandCapabilities Empty { get; } = new( new Dictionary<Type, object>() );
internal CommandCapabilities( IReadOnlyDictionary<Type, object> values )
{
_values = new Dictionary<Type, object>( values );
}
public T GetService<T>() where T : class => _values.TryGetValue( typeof( T ), out var value ) ? (T)value : null;
}