I had to investigate some exception at production, and then I found this code that uses FluentValidation:
(inside async method)
var validator = new SomeCustomValidator();
var validationResult = validator.ValidateAsync(request).Result.ValidateRepositoryAsync(request, someRepository);
PS: The method ValidateRepositoryAsync
is a custom extension from our project.
To do a little bit refactoring on it, I just changed to:
(inside async method)
ValidationResult validationResult;
var validator = new SomeCustomValidator();
validationResult = await validator.ValidateAsync(request);
validationResult = await validationResult.ValidateRepositoryAsync(request, someRepository);
So, this codes needs to execute first the ValidateAsync
, await for it, and then with the result execute the ValidateRepositoryAsync
.
Now the question is, I was wondering if there's another way to do that, maybe in an one line of code, with ContinueWith, or this is the cleaner way to solve this issue?
That's the closer I got, but that doesn't seem cleaner to read:
var validator = new SomeCustomValidator();
var validationResult = await (await validator.ValidateAsync(request)).ValidateRepositoryAsync(request, someRepository);
Any thoughts on that?
Thanks!