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
Solution 1: Pathik Patel
In the case of
lazyPut, it only creates the instance, and it'll be instantiated only when is used, check more details here
Solution 2: Ivo
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.
Solution 3: Tuan
Get.put()will put immediately
Get.lazyPut()will put when you need it