Skip to content

Benefits over singleton #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ncuillery opened this issue Jun 16, 2020 · 3 comments
Closed

Benefits over singleton #87

ncuillery opened this issue Jun 16, 2020 · 3 comments

Comments

@ncuillery
Copy link

I'm wondering what are the benefits of this package over plain simple Dart singletons.

With singletons, you can make an instance of a class available everywhere in your code base, by leveraging the Dart import mechanism (no global variable).

So I'm wondering why would I use get_it. So far, I see that get_it offers a better testability.

It also seems that the laziness would require a bit of boilerplate in singleton, that I wouldn't have to write with get_it

Is there anything else?

@creativecreatorormaybenot

Seems like I had the same question just now 😄 (#88)

My question is a bit more concrete than yours → possible answer to your question: get_it supports a lot more than plain singletons, like named singletons, async stuff, non-lazy, etc.

@escamoteur
Copy link
Collaborator

Main difference to a singleton is that you can easily switch out implementations.

Furthermore:

  • Singletons normally can't be reasigned or resetted
  • GetIt offers besides Singletons Factories
  • It suports async Singletons
  • It has support for async startup synchronisation

@ncuillery
Copy link
Author

Thanks for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants