public async Task <IQueryResult <TQuery, TResult> > Execute <TQuery, TResult>(TQuery query) where TQuery : IQuery <TResult> { var queryHandler = this._dependencyResolver.Get <IQueryHandler <TQuery, TResult> >(); var result = new QueryExecutionResult <TQuery, TResult>(this._dependencyResolver); var success = await queryHandler.CheckContext(query, this._context, result) && await queryHandler.CheckParameters(query, result) && await this.ExecuteQueryHandler(query, queryHandler, result); return(result); }
public async Task <IQueryResult <TResult> > ExecuteInternal <TQuery, TResult>(TQuery command, Func <TQuery, TResult> resultAccessor) where TQuery : IQuery { var result = new QueryExecutionResult <TResult>(teclyn); this.CheckContextInternal(command, result); this.CheckParametersInternal(command, result); if (!result.Errors.Any()) { // execute await command.Execute(result); // get result result.Result = resultAccessor(command); result.SetSuccess(); } return(result); }
private async Task <bool> ExecuteQueryHandler <TQuery, TResult>(TQuery command, IQueryHandler <TQuery, TResult> queryHandler, QueryExecutionResult <TQuery, TResult> result) where TQuery : IQuery <TResult> { try { var handlerResult = await queryHandler.Execute(command, result); result.SetSuccess(); result.Result = handlerResult; return(true); } catch (Exception exception) { result.SetFailure(exception.ToString()); return(false); } }
private void CheckContextInternal(IQuery query, QueryExecutionResult result) { result.ContextIsValid = query.CheckContext(context, result); }
private void CheckParametersInternal(IQuery query, QueryExecutionResult result) { result.ParametersAreValid = query.CheckParameters(result); }
public UserFriendlyQueryResult(QueryExecutionResult <TResult> result) { this.Success = result.Success; this.Errors = result.Errors.ToArray(); this.Result = result.Result; }