Comments (5)
Can you explain to me how a lazy singleton would help you in this aspect?
I'm pretty sure there are better ways to achieve the same?
Did you have a closer look at get_it scopes?
from get_it.
If we declare Singletons they will be create as soon as they are declared and will live in memory. Scopes allow us to reduce their footprint, but then we have to be controlling scopes all over the app. I don't want to use scopes for several reasons:
1 - I have a Storage
class that's used in many screens and flows in my app, but not in all of them. The ones who use it, I want them to have the same Singleton with the same internal cache. It's acceptable if it's created once by one screen and it lives there in memory, the problem is when all the singletons are created at startup and bloat the memory. If I use scopes, I will have to be micro-managing the scopes across the entire app, and I would also like to share singletons across scopes.
Let's say I have pages A, B, C, D and E. I want the same Storage
on pages A, B and C, but not on D and E. Those pages are in a bottom navigator, so they are not related to each other.
2 - The less coupling my app has on third party libraries, the better. No offense, get_it is very useful, but I rather "contain" how much it influences my app in case I need to replace it one day. I declare the dependencies when the app starts and I make all the singletons and factories call each other. then I create the objects I want on a given page. This way I only have get_it in 2 places: App Initialization and Pages initialization.
from get_it.
from get_it.
unless they cache images or other huge Data blocks.
So you agree with me that are cases where Singletons can bloat your app's memory, so why not make the lib ready to provide to us the tools to control the memory in any way we want?
from get_it.
See our other discussion
from get_it.
Related Issues (20)
- Async factorties should have a `dependsOn` HOT 20
- `registerLazySingletonAsync` not working with `dependsOn` HOT 3
- Add new type of scope that is independ of the scope stack HOT 1
- Build error in version 7.6.1 HOT 7
- unlisted from pub.dev? HOT 4
- Null check operator used on a null value with allReady on hot refresh HOT 2
- Can't register AutoRoute v6 with GetIt HOT 2
- Bad state: GetIt: Object/factory with type AdviceRepoImpl is not registered inside GetIt. HOT 1
- Check implementation of `WillSignalReady` on subclasses HOT 1
- Collections Multibinding HOT 5
- Questions about the registerFactory HOT 2
- Error on example code for addListener HOT 10
- Concerns about Get_It HOT 4
- Need Help: Dependency Problem with GetIt in vm:entry-point Pragma HOT 1
- `unregister<T>` unregisters all services of type `T` HOT 9
- Webview shows blank untill the app is sent to background and brought forward again ... HOT 1
- trying to upgarde the package to 7.6.9 HOT 9
- Make pushing a new scope atomic. HOT 3
- Get it problem HOT 1
- [feature request] `registerCachedInstance`? HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from get_it.