The cptroot states require a module wherever you need it, instead of passing it, because the argument is safe and also much simpler. However, you should view any call request as a hard-coded dependency that you cannot easily change. For instance. if you want to mock a module to test these hard-coded dependencies, it will hurt.
Thus, passing the module instance as an argument, instead of just requiring it again and again, reduces the number of hard-coded dependencies, because now you are introducing this dependency. For instance. in your tests, it will be useful for you to easily introduce a layout instead.
If you take this road, you will want to use the dependency injection container, which will help you enter all your dependencies and get rid of all the hard-coded calls. To choose an addiction injection container appropriate for your project, you should read this excellent article . Also check out Fire Up! which I implemented.
source share