Skip to content
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

Single instance vs Scoped instance #11

Closed
Errechydy opened this issue Mar 15, 2020 · 2 comments
Closed

Single instance vs Scoped instance #11

Errechydy opened this issue Mar 15, 2020 · 2 comments

Comments

@Errechydy
Copy link

What's the difference between exposing BLoC classes as single instance vs scoped instance? is it just a way to help structuring the code or has an effect on the app performance?

@SAGARSURI
Copy link
Owner

SAGARSURI commented Mar 16, 2020

When I implemented DI in this project. I didn't find a good solution for scoped instance. But in my opinion, you should scope your BLoC instances instead of making them all singleton because you should create an object when it is required and destroy them when its job is over.

I will look at the current implementation and see if there is a better solution to create scoped instances.

@Errechydy
Copy link
Author

You said "you should create an object when it is required and destroy them when its job is over", but that happened with singleton too, it got created only when you enter the screen and it got destroyed when you leave it.
For example let's assume you created a BLoC for a "About us" which almost no one visit it, even if the BLoC of it is singleton and you can access it from anywhere it got created only once you are in About Us screen and it got destroyed when you leave it. so even if can access it from anywhere you only call it once you are in About Us screen.
Is what i'm saying true or did i miss something?

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

2 participants