public static IServiceCollection AddQuery <TQuery, TResult, TQueryHandler>(this IServiceCollection source) where TQuery : IQuery <TResult> where TQueryHandler : class, IQueryHandler <TQuery, TResult> { AssertArguments.NotNull(source, nameof(source)); return(source.AddScoped <IQueryHandler <TQuery, TResult>, TQueryHandler>()); }
public virtual async Task <PaginatedResult <TResult> > ExecuteAsync(TQuery query) { AssertArguments.NotNull(query, nameof(query)); var unfilteredQuery = ExecuteCore(query); var filteredQuery = unfilteredQuery .Skip(query.Skip) .Take(query.Limit); return(new PaginatedResult <TResult>( query.Skip, query.Limit, await unfilteredQuery.CountAsync(), await filteredQuery.ToArrayAsync() )); }
public virtual async Task <TResult> ProcessAsync <TResult>(IQuery <TResult> query) { AssertArguments.NotNull(query, nameof(query)); // finding the query handler by using query type. we will // throw argument exception when no handler registered for // specified query type. var handlerType = typeof(IQueryHandler <,>).MakeGenericType(query.GetType(), typeof(TResult)); // TODO: using service provider to resolve query handler dependencies. var handler = ServiceProvider.GetService(handlerType) as IQueryHandler <TResult>; AssertArguments.IsTrue( handler != null, $"'{handlerType.Name}' is not a valid query handler type.", "query" ); return(await handler.ExecuteAsync(query)); }
public BookingQueryHandler(DreamlinesContext dbContext) { AssertArguments.NotNull(dbContext, nameof(dbContext)); Context = dbContext; }
public DefaultQueryProcessor(IServiceProvider serviceProvider) { AssertArguments.NotNull(serviceProvider, nameof(serviceProvider)); ServiceProvider = serviceProvider; }
public SalesUnitQueryHandler(DreamlinesContext context) { AssertArguments.NotNull(context, nameof(context)); Context = context; }