1

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?

3
  • this might help stackoverflow.com/questions/15313205/… Commented 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? Commented Mar 18, 2013 at 16:51
  • In my case it's fixed but it'd be interesting to know the answer for both cases. Commented Mar 18, 2013 at 17:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I think you're right. Using one service to do all the talking with all the feeds is probably the way forward. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.