I am new to Getx dependency injection so can some one explain me benefits of put and lazyput and Also tell me when to use put and when to use lazyput
CodePudding user response:
To my understanding put
already puts an instance of the class directly in memory while lazyPut
just puts a builder for it in it.
A benefit of lazyPut
is that it saves memory until you actually find
it. And you can also put more complex code in the builder for it. Another benefit of lazyPut
is that you can also say fenix: true
on it which means it's able to be reconstructed in case it got disposed of before.
I would think the only benefit of using put
is that find
should be slightly faster then when called because it doesn't need to call a builder first to get the instance. I don't know if there are other benefits.
CodePudding user response:
In the case of lazyPut
, it only creates the instance, and it'll be instantiated only when is used, check more details here
CodePudding user response:
Short answer
Get.put()
will put immediatelyGet.lazyPut()
will put when you need it