Welcome Guest, Not a member yet? Register   Sign In
Poll: D.I. vs Service locator?
You do not have permission to vote in this poll.
yes
37.50%
3 37.50%
no
25.00%
2 25.00%
maybe
37.50%
3 37.50%
Total 8 vote(s) 100%
* You voted for this item. [Show Results]

True D.I. vs service locator.
#3

(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?
Reply


Messages In This Thread
True D.I. vs service locator. - by skunkbad - 04-09-2015, 10:19 PM
RE: True D.I. vs service locator. - by dmyers - 04-10-2015, 06:44 AM
RE: True D.I. vs service locator. - by skunkbad - 04-10-2015, 06:59 AM
RE: True D.I. vs service locator. - by dmyers - 04-10-2015, 07:09 AM
RE: True D.I. vs service locator. - by kilishan - 07-26-2015, 08:17 PM
RE: True D.I. vs service locator. - by mwhitney - 07-27-2015, 01:19 PM
RE: True D.I. vs service locator. - by kenjis - 07-27-2015, 02:33 PM
RE: True D.I. vs service locator. - by kilishan - 07-27-2015, 07:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB