You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
I understand that services in AngularJS are singletons. That's fine and often it is exactly what you want. But once you begin to build stateful services you might want to get a fresh instance per controller. How would you achieve this?
For example, let's say you build a twitter reader and you have built a twitterServices that holds state like the current username, the fetched stream data, the pagination position etc. Now let's say you want the UI to be tab based so that you get another stream view for another username that you own. You would also like to use the twitterService that you built but obviously you would like to use another instance.
My proposal would be to let people configure if a service should be injected as singleton or with a fresh instance.
I wrote a IOC library that does dependency injection pretty much the same way that Angular does it but lets you decide about the lifecycle of the instances: https://github.com/cburgdorf/swiftcore.js