dotnet-cqrs/OpenHarbor.CQRS/Discovery/QueryDiscovery.cs

24 lines
829 B
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using OpenHarbor.CQRS.Abstractions.Discovery;
namespace OpenHarbor.CQRS.Discovery;
public sealed class QueryDiscovery : IQueryDiscovery
{
private readonly IEnumerable<IQueryMeta> _queryMetas;
public QueryDiscovery(IEnumerable<IQueryMeta> queryMetas)
{
_queryMetas = queryMetas;
}
public IEnumerable<IQueryMeta> GetQueries() => _queryMetas;
public IQueryMeta FindQuery(string name) => _queryMetas.FirstOrDefault(t => t.Name == name);
public IQueryMeta FindQuery(Type queryType) => _queryMetas.FirstOrDefault(t => t.QueryType == queryType);
public bool QueryExists(string name) => _queryMetas.Any(t => t.Name == name);
public bool QueryExists(Type queryType) => _queryMetas.Any(t => t.QueryType == queryType);
}