Why is DI needed?
DI is not a must for all projects. Until now, our Restaurants app worked just fine without any DI incorporated. Yet, while not including DI might not seem like a big issue, by incorporating it you bring a lot of benefits to your project; the most notable advantages are that you can do the following:
- Write less boilerplate code.
- Write testable classes.
Let's cover these two next.
Write less boilerplate code
Let's circle back to our Restaurants app, and let's have a look at how we instantiate the Retrofit interface within the RestaurantsRepository
class:
class RestaurantsRepository { private var restInterface: RestaurantsApiService = Retrofit.Builder() .addConverterFactory( GsonConverterFactory...