Skip to content

Commit

Permalink
Use overridable HostContext.Async for Validator RequestFilterAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed May 9, 2017
1 parent 3cd0467 commit b0aacff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/ServiceStack/AsyncContext.cs
Expand Up @@ -43,6 +43,11 @@ public virtual Task<object> ContinueWith(IRequest req, Task task, Func<Task, obj
return task.ContinueWith(fn);
}

public virtual Task<object> ContinueWith<T>(IRequest req, Task<T> task, Func<Task<T>, object> fn)
{
return task.ContinueWith(fn);
}

public virtual Task<T> ContinueWith<T>(IRequest req, Task<object> task, Func<Task<object>, T> fn)
{
return task.ContinueWith(fn);
Expand Down
10 changes: 6 additions & 4 deletions src/ServiceStack/Validation/ValidationFilters.cs
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using ServiceStack.FluentValidation;
using ServiceStack.Web;
Expand Down Expand Up @@ -46,19 +47,20 @@ public static Task RequestFilterAsync(IRequest req, IResponse res, object reques
if (validator == null || !validator.HasAsyncValidators(ruleSet))
return TypeConstants.EmptyTask;

return validator.ValidateAsync(
var validateTask = validator.ValidateAsync(
new ValidationContext(requestDto, null, new MultiRuleSetValidatorSelector(ruleSet))
{
Request = req
})
.ContinueWith(t =>
});

return HostContext.Async.ContinueWith(req, validateTask, t =>
{
var validationResult = t.Result;
if (validationResult.IsValid)
return TypeConstants.TrueTask;
var errorResponse = HostContext.RaiseServiceException(req, requestDto, validationResult.ToException())
?? DtoUtils.CreateErrorResponse(requestDto, validationResult.ToErrorResult());
?? DtoUtils.CreateErrorResponse(requestDto, validationResult.ToErrorResult());
var validationFeature = HostContext.GetPlugin<ValidationFeature>();
if (validationFeature?.ErrorResponseFilter != null)
Expand Down

0 comments on commit b0aacff

Please sign in to comment.