Implementing the Inversion of Control Principle
In Chapter 6, we started working on our Model layer by introducing the repository pattern and exploring its various benefits. One of the main themes of patterns in this book is decoupling responsibilities, which leads to improved flexibility, scalability, and maintainability. The first crucial step in achieving this is extracting all the logic of the Model layer into repositories. The next logical step is to follow the inversion of control (IoC) principle in order to design a good app architecture.
In this chapter, we will learn how to provide our repositories to our blocs (view models, notifiers, providers, and so on) in a way that allows us to easily replace these dependencies, control their instantiation, and seamlessly test our code in the future. We will discuss the rationale behind patterns such as dependency injection (DI) and service locator (SL), and explore their practical implementation along with their benefits and limitations...