My understanding of angular services is that they are used to access external data sources amongst other things.
So let's assume I have a service to access feeds, that deals with the ATOM parsing, etc.
Now, let's assume a controller needs to access several feeds.
Is there a way for me to parameterize services as they are instantiated? Since services are singletons, do I need a service factory factory? Should I be using the same service and passing details of the particular feed each time? What if I need to make more than one calls to the same feed and would like a dedicated object to speak with? (think websockets instead of feeds).
Is there another approach altogether that would work for this?
-
this might help stackoverflow.com/questions/15313205/…charlietfl– charlietfl2013年03月17日 18:49:19 +00:00Commented Mar 17, 2013 at 18:49
-
Where does your app get the set of possible feeds? Is this a known/fixed set, or is it dynamic -- i.e., can a user provide feed details at run time?Mark Rajcok– Mark Rajcok2013年03月18日 16:51:54 +00:00Commented Mar 18, 2013 at 16:51
-
In my case it's fixed but it'd be interesting to know the answer for both cases.Alexandros Marinos– Alexandros Marinos2013年03月18日 17:33:34 +00:00Commented Mar 18, 2013 at 17:33
1 Answer 1
Is there a way for me to parameterize services as they are instantiated?
Not really. You can inject things into a service – e.g., another service – but I don't think that will help you here.
Since services are singletons, do I need a service factory factory?
I don't know how you would write that, but again, I don't think it would help here.
Should I be using the same service and passing details of the particular feed each time?
Well, as I asked in the comments, if you are dealing with a fixed set of feeds, I would hard-code them into the service (or maybe have the service fetch them from a configuration file on the server), and allow the controller to ask for them by name or some ID.
If you need something more dynamic, then I think you'd have to pass in the feed details to the service.
In either case, I think one "atomFeed" service would be sufficient.
What if I need to make more than one call to the same feed and would like a dedicated object to speak with?
I would probably still use one service. I'm not sure what the issue is here though.
1 Comment
Explore related questions
See similar questions with these tags.