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.

  • 1
    Which approach most effectively meets your non-functional software requirements for maintainability? – Robert Harvey May 5 '17 at 16:23
  • From my point of view command, command handler approach is more maintainable. – Hasibul May 5 '17 at 16:56
  • There you go ... – Robert Harvey May 5 '17 at 17:13
  • Do it both ways and see if the difference is just naming – Ewan May 5 '17 at 18:00
  • not so, If I call service class directly from controller then everything happens inside service class. If I do it from command handler then validation and payload preparation goes there (inside handler) and service class only deal with its own business logic.. – Hasibul May 5 '17 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.