Choosing the Right Injection
Learn to choose the ideal injection method based on the use case and scenario.
Why choosing the right injection is important
GetX offers quite several methods to inject dependencies. While each is fundamentally different and caters to a specific use case, we can still misinterpret the use cases in which a particular method should be used. Choosing the wrong injection method can hamper app performance and invite unwanted errors, so it’s important that we learn to make the right choice. This lesson acts as a guide that teaches us the function of each injection method and the use case it caters to.
Choosing the Get.put
method
Immediate injection:
Get.put
not only initializes the dependency but also callsGet.find
internally, making the dependency available immediately. So, use it when we want immediate access to the dependency. This is the most common scenario, and we’ll useGet.put
more often than other methods.Prevent deletion: Dependencies initialized with
Get.put
can be prevented from getting ...