I am going to build a simple asp.net web api application which will send request to 3rd party service and then return back the response to client.
Before sending request to external service,
I need to prepare request payload from DB and also need to validate it.
After validation I will send this payload to 3rd party service through http-client and then return the response to the client.
Here I can create a service class which will do everything for me like model preparation, validation, sending request to external service and return back the response.Then I can call the service from controller class. This is one approach.
Another approach can be, I can create a command, command handler and service class. In this case payload preparation and validation will be performed from the command handler and my service class will be clean. But in this approach problem is “according to rule/ best practice command handler should be void” but here I need immediate response from the 3rd party service.
So my question is
What should be best solution for this scenario. Shall I use service class directly from controller and service class will do all operations?
I will use command handler with return type?
Expecting your valuable suggestion.
Thanks in advance.