internal CommandFilterGrouping GetFilterGrouping() { Collection <FilterInfo> currentFilterPipeline = this.GetFilterPipeline(); if (this.filterGrouping == null || this.filterPipelineForGrouping != currentFilterPipeline) { this.filterGrouping = new CommandFilterGrouping(currentFilterPipeline); this.filterPipelineForGrouping = currentFilterPipeline; } return(this.filterGrouping); }
/// <summary> /// Execute the request via the worker. /// </summary> /// <param name="request">The <see cref="HandlerRequest"/> to execute.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> to cancel the execution.</param> /// <returns>The result of the command, if any.</returns> public Task <HandlerResponse> ExecuteAsync(CommandHandlerRequest request, CancellationToken cancellationToken) { if (request == null) { throw Error.ArgumentNull("request"); } cancellationToken.ThrowIfCancellationRequested(); ServicesContainer servicesContainer = request.Configuration.Services; ICommandHandlerSelector handlerSelector = servicesContainer.GetHandlerSelector(); CommandHandlerDescriptor descriptor = handlerSelector.SelectHandler(request); ICommandHandler commandHandler = descriptor.CreateHandler(request); if (commandHandler == null) { throw CreateHandlerNotFoundException(descriptor); } request.RegisterForDispose(commandHandler, true); CommandHandlerContext context = new CommandHandlerContext(request, descriptor); context.Handler = commandHandler; commandHandler.CommandContext = context; CommandFilterGrouping commandFilterGrouping = descriptor.GetFilterGrouping(); ICommandHandlerResult result = new CommandHandlerFilterResult(context, servicesContainer, commandFilterGrouping.CommandHandlerFilters); if (descriptor.RetryPolicy != RetryPolicy.NoRetry) { result = new RetryHandlerResult(descriptor.RetryPolicy, result); } if (commandFilterGrouping.ExceptionFilters.Length > 0) { IExceptionLogger exceptionLogger = ExceptionServices.GetLogger(servicesContainer); IExceptionHandler exceptionHandler = ExceptionServices.GetHandler(servicesContainer); result = new ExceptionFilterResult(context, commandFilterGrouping.ExceptionFilters, exceptionLogger, exceptionHandler, result); } return(result.ExecuteAsync(cancellationToken)); }
private static CommandFilterGrouping CreateTestableFilterGrouping() { var filters = new[] { new FilterInfo(new Mock<ICommandHandlerFilter>().Object, FilterScope.Global), new FilterInfo(new Mock<ExceptionFilterAttribute>().Object, FilterScope.Global), new FilterInfo(new Mock<IFilter>().Object, FilterScope.Global), new FilterInfo(new Mock<ICommandHandlerFilter>().Object, FilterScope.Global), new FilterInfo(new Mock<ExceptionFilterAttribute>().Object, FilterScope.Global), new FilterInfo(new Mock<ICommandHandlerFilter>().Object, FilterScope.Global), new FilterInfo(new Mock<IFilter>().Object, FilterScope.Global), new FilterInfo(new Mock<ExceptionFilterAttribute>().Object, FilterScope.Global), new FilterInfo(new Mock<ICommandHandlerFilter>().Object, FilterScope.Global), new FilterInfo(new Mock<ExceptionFilterAttribute>().Object, FilterScope.Global), new FilterInfo(new Mock<ExceptionFilterAttribute>().Object, FilterScope.Global) }; CommandFilterGrouping group = new CommandFilterGrouping(filters); return group; }
private static CommandFilterGrouping CreateTestableFilterGrouping() { var filters = new[] { new FilterInfo(new Mock <ICommandHandlerFilter>().Object, FilterScope.Global), new FilterInfo(new Mock <ExceptionFilterAttribute>().Object, FilterScope.Global), new FilterInfo(new Mock <IFilter>().Object, FilterScope.Global), new FilterInfo(new Mock <ICommandHandlerFilter>().Object, FilterScope.Global), new FilterInfo(new Mock <ExceptionFilterAttribute>().Object, FilterScope.Global), new FilterInfo(new Mock <ICommandHandlerFilter>().Object, FilterScope.Global), new FilterInfo(new Mock <IFilter>().Object, FilterScope.Global), new FilterInfo(new Mock <ExceptionFilterAttribute>().Object, FilterScope.Global), new FilterInfo(new Mock <ICommandHandlerFilter>().Object, FilterScope.Global), new FilterInfo(new Mock <ExceptionFilterAttribute>().Object, FilterScope.Global), new FilterInfo(new Mock <ExceptionFilterAttribute>().Object, FilterScope.Global) }; CommandFilterGrouping group = new CommandFilterGrouping(filters); return(group); }