Best practices for calling services and handling responses
Hey guys,
Just looking for some general info on the best way to handle service requests. From all I've read it seems the general flow is to have a command (or possibly a mediator) call a method on a service which in-turn fires of a request for some data. The service waits for the data to return, then dispatches an event to notify the application that the data has been received.
That all makes perfect sense. What I'm wondering is how to handle the returned data. So let's say I wanted to take the data I got back and update one of my models. Would I then need to create another command, tie it to the event, and update the model from my command? From what I can tell, that is the best-practice. My concern is that it seems I could quickly get into a spot where I am having to create a large amount of commands to handle all these requests/updates.
Is there perhaps a better way of handling this?
Thanks!
-Kyle
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Kyle on 01 Jul, 2013 10:54 PM
Just found another thread that mentions simply injecting the model into the service.. Perhaps this will cut down on the need to create too many commands..
Support Staff 2 Posted by Ondina D.F. on 02 Jul, 2013 07:32 AM
Hi Kyle,
If you inject the Model into a Service, it is better to inject it as an interface.
Another approach is to use factories inside your service to populate the models with the service’s results.
Detaining the command that calls the service and let the command update the model with the results, may be also an option.
Ondina
3 Posted by Kyle on 02 Jul, 2013 04:20 PM
Thanks Ondina! I think at this point I'll look into creating parser classes to handle the data parsing/packaging, then utilize those classes in the service to generate my objects and use them to update my model (from the service).
I'd like to keep this thread open for now in case anyone has other/better suggestions...
=]
Ondina D.F. closed this discussion on 30 Aug, 2013 07:55 AM.