(04-10-2015, 06:59 AM)skunkbad Wrote: (04-10-2015, 06:44 AM)dmyers Wrote: I messed around with Pimple a bit just out of curiosity. My question to you so I can understand what exactly you are looking for is, how is attaching objects to the Pimple Container and passing it into the class any different than attaching the objects to the CodeIgniter "Super Object" and calling it directly ( get_instance()->my_library->do_work() ?) I understand for testing sending in mocks (when using DI) is a little easier but, it seems the CodeIgniter team has unit testing working regardless. Besides unit testing what other benefits am I not understanding?
As a side note:
I assume most dev's like me add a ci() function as a shortened version of the get_instance() function
DMyers
You are right, that passing the Pimple container around is sort of like the current way CI has a super object, but Pimple can provide true D.I. as well. You can actually do both at the same time if you wish. Another thing I have done is create a static class to complement the standard CI class, so that I have even more flexibility by being able to call the CI class through the container, through the DI object, or through the static class. It's pretty nice for me, but what I'm asking is that whoever makes the decision as to what CI4 will implement, consider all of these things.
As has been the case with CI in the past, I know one of the main objectives is to keep it easy to use, so that's why it's important to review and talk about this issue. How would you like to see DI handled?
skunkbad, what do you mean when you say "
provide true D.I." what are some of the other benefits of using DI Vs a service locator besides the unit test stuff I listed above? (here is you big chance to sell others reading this on DI Vs keeping as is).
DMyers