/// <inheritdoc /> public Task <TResult> ProcessAsync <TResult>(IQuery <TResult> query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } Task <TResult> GetResultAsync(IQuery <TResult> query) { var handler = _handlerResolver.ResolveQueryHandler(query, typeof(IQueryHandlerAsync <,>)); var handleMethod = handler.GetType().GetMethod("HandleAsync", new[] { query.GetType() }); return((Task <TResult>)handleMethod.Invoke(handler, new object[] { query })); } if (query is ICacheableQuery <TResult> cacheableQuery) { if (string.IsNullOrEmpty(cacheableQuery.CacheKey)) { throw new QueryException("Cache key is required."); } return(_cacheManager.GetOrSetAsync( cacheableQuery.CacheKey, cacheableQuery.CacheTime ?? _options.CacheTime, () => GetResultAsync(query))); } return(GetResultAsync(query)); }
/// <inheritdoc /> public Task <TResult> ProcessAsync <TResult>(IQuery <TResult> query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } var handler = _handlerResolver.ResolveQueryHandler(query, typeof(IQueryHandlerAsync <,>)); var handleMethod = handler.GetType().GetMethod("HandleAsync"); return((Task <TResult>)handleMethod.Invoke(handler, new object[] { query })); }
public async Task <TQueryResult> QueryAsync <TQueryResult>(IQuery <TQueryResult> query) { var handlerInstance = (dynamic)_handlerResolver.ResolveQueryHandler(query, typeof(IQueryHandler <,>)); var result = await handlerInstance.HandleAsync((dynamic)query); if (result.IsSuccess) { return(result.Value); } throw new GeneralException(result.Error); }