Has anyone used FluentValidation in conjunction with a Refit Client?
As part of a system I'm working on, I call out to various REST services and I'd like to use FluentValidation to validate the typed responses in a uniform manner.
Obviously I could manually validate after each call to the Refit client inline but I was wondering whether there was any scope to automatically find relevant validators and invoke them.
I guess I'm looking at something similar to the validation behavior pattern in Mediatr.
A couple of thoughts I had were:
1. Decorate each client interface with a validating wrapper
This would require using an IoC container which supports decoration and would mean I'd have to create an implementation of each client interface which would then validate the responses coming back from refit.
2. Add a validating DelegatingHandler to the pipeline
This would probably end up having to deserialize the content - perform the validation - and then return the response to the next handler in the chain. This is probably OK where the content is small...
3. Use a custom validating JsonConverter
Here I would wrap a Json.Net converter and in the Deserialize perform the validation.
Or is there some feature of Refit I've missed which would help with this, or does what I'm suggesting just seem crazy?!
Thanks,
Nick.