...

/

Choosing the Right Injection

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

  1. Immediate injection: Get.put not only initializes the dependency but also calls Get.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 use Get.put more often than other methods.

  2. Prevent deletion: Dependencies initialized with Get.put can be prevented from getting ...