using System; using System.Collections.Generic; using System.Linq; using OpenHarbor.CQRS.Abstractions.Discovery; namespace OpenHarbor.CQRS.Discovery; public sealed class CommandDiscovery : ICommandDiscovery { private readonly IEnumerable _commandMetas; public CommandDiscovery(IEnumerable commandMetas) { _commandMetas = commandMetas; } public IEnumerable GetCommands() => _commandMetas; public ICommandMeta FindCommand(string name) => _commandMetas.FirstOrDefault(t => t.Name == name); public ICommandMeta FindCommand(Type commandType) => _commandMetas.FirstOrDefault(t => t.CommandType == commandType); public bool CommandExists(string name) => _commandMetas.Any(t => t.Name == name); public bool CommandExists(Type commandType) => _commandMetas.Any(t => t.CommandType == commandType); }