Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Allow non-singleton services #1011

@cburgdorf

Description

@cburgdorf

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

I think Angular should adopt that.

Previous to the creation of this ticket I had a little discussion about that in the group that I just reference here: https://groups.google.com/forum/#!msg/angular/eeooXXaYFj0/C2FIWfse58cJ

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions