public virtual Task <TResult> DispatchAsync <TQuery, TResult>(TQuery query, CancellationToken cancellationToken) where TQuery : IQuery <TResult>
        {
            cancellationToken.ThrowIfCancellationRequested();

            IAsyncQueryHandler <TQuery, TResult> handler = this.Resolve <TQuery, TResult>(cancellationToken);

            return(handler.HandleAsync(query, cancellationToken));
        }
        public async Task <TResult> HandleAsync(TFilter filter, CancellationToken cancellationToken = default)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            filter.EnsureIsValid();

            return(await queryHandler.HandleAsync(filter, cancellationToken).ConfigureAwait(false));
        }
Example #3
0
 public Task <Result <Unit, Exception> > InitializeAsync(CancellationToken cancellationToken = default)
 {
     // if database has not already been initialized with seed data, do so
     return(_getSchoolInitializationStatusQueryHandler.HandleAsync(new GetSchoolInitializationStatusQuery(), cancellationToken)
            .BindIfFalseAsync(async() =>
     {
         return await _saveStudentDataCommandHandler.HandleAsync(new SaveStudentDataCommand(CreateStudentSeedData()), cancellationToken)
         .BindAsync(_ => _saveCourseDataCommandHandler.HandleAsync(new SaveCourseDataCommand(CreateCourseSeedData()), cancellationToken))
         .BindAsync(_ => _saveEnrollmentDataCommandHandler.HandleAsync(new SaveEnrollmentDataCommand(CreateEnrollmentSeedData()), cancellationToken));
     }));
 }
        public async Task <TResult> HandleAsync(TQuery query, CancellationToken cancellationToken)
        {
            var validator = (IValidator <TQuery>)((IServiceProvider)_container).GetService(typeof(IValidator <TQuery>));

            if (validator != null)
            {
                await ValidateUtil.ValidateAsync(async() =>
                {
                    await validator.ValidateAndThrowAsync(query, ValidationRuleSet.InsertUpdate);
                });
            }

            return(await _decorated.HandleAsync(query, cancellationToken));
        }
        public async Task <TResult> HandleAsync(TQuery query)
        {
            var result = await _innerHandler.HandleAsync(query).ConfigureAwait(false);

            string resultString;

            try
            {
                resultString = result.ToJson();
            }
            catch (Exception)
            {
                resultString = "{}";
            }

            _logger.Info($"{query.GetType().Name}  ====>  {_innerHandler.GetType().Name}: {query.ToJson()} => {resultString}");

            return(result);
        }
 public Task <TResult> HandleAsync(TFilter filter, CancellationToken cancellationToken = default)
 {
     return(CreateAsyncPolicy()
            .ExecuteAsync(async() => await queryHandler.HandleAsync(filter, cancellationToken)));
 }