<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Jason Lotito - Latest Comments</title><link>http://jasonlotito.disqus.com/</link><description></description><atom:link href="https://jasonlotito.disqus.com/comments.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 20 Mar 2015 16:11:38 -0000</lastBuildDate><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918724682</link><description>&lt;p&gt;Alright, it comes from this &lt;a href="https://twitter.com/drupalizeme/status/578920462673186817" rel="nofollow noopener" target="_blank" title="https://twitter.com/drupalizeme/status/578920462673186817"&gt;tweet&lt;/a&gt;. Maybe you should add an info message at the top of this post. So other people see that this post is deprecated.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Sandro Keil</dc:creator><pubDate>Fri, 20 Mar 2015 16:11:38 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918690765</link><description>&lt;p&gt;This article was written, iirc, after reading numerous others talking about DI and SL systems that are essentially: $foo-&amp;gt;get('logger') and then using factories behind the scenes.  Basically, you were using plain old strings, and there was no way to find out how the logger was created without knowing the entire system.  I love my IDE, and if I can't ctrl+click my way to victory, there is something wrong. =)&lt;/p&gt;&lt;p&gt;I've wanted to revisit this approach and correct some things and better answer some of the criticisms, but the code base I work on day-to-day is still using PHP 5.3, so I haven't had the opportunity to really see how it works in a real system.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jason Lotito</dc:creator><pubDate>Fri, 20 Mar 2015 15:51:41 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918642656</link><description>&lt;p&gt;Yeah, our service locator has all the downsides associated with the pattern. We came from almost all global functions so this is just an iteration while we slowly migrate towards DI.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mrclay</dc:creator><pubDate>Fri, 20 Mar 2015 15:24:52 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918598480</link><description>&lt;p&gt;&amp;gt;  It looks like a workaround for a missing service locator?&lt;br&gt;Yes.  The Traits could implement the factories themselves.  As mentioned though, this is an old article, and here mostly for posterity.  For some reason, there are a number of people commenting on it today.  *shrug*&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jason Lotito</dc:creator><pubDate>Fri, 20 Mar 2015 14:59:10 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918595868</link><description>&lt;p&gt;My issue with this implementation is the non-obvious dependency on session, and potentially anything that _elgg_services() could return.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jason Lotito</dc:creator><pubDate>Fri, 20 Mar 2015 14:57:39 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918581495</link><description>&lt;p&gt;Yep.  It's an old article, and something I experimented with.  Don't have the comments from the original article, where we discussed the same basic things.  It's here mostly for posterity.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jason Lotito</dc:creator><pubDate>Fri, 20 Mar 2015 14:49:24 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918409263</link><description>&lt;p&gt;I don't like this approach. It looks like a workaround for a missing service locator? Please have a look at the service manager of zf2 and inject your dependencies and use factories. A Trait is not the solution in this case.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Sandro Keil</dc:creator><pubDate>Fri, 20 Mar 2015 13:14:37 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918409180</link><description>&lt;p&gt;In Elgg our SL is returned by a global function _elgg_services() and here's how we might use it: &lt;a href="https://github.com/Elgg/Elgg/blob/1.x/engine/classes/ElggObject.php#L269" rel="nofollow noopener" target="_blank" title="https://github.com/Elgg/Elgg/blob/1.x/engine/classes/ElggObject.php#L269"&gt;https://github.com/Elgg/Elg...&lt;/a&gt;&lt;/p&gt;&lt;p&gt;We hint the type of properties on it here: &lt;a href="https://github.com/Elgg/Elgg/blob/1.x/engine/classes/Elgg/Di/ServiceProvider.php#L14" rel="nofollow noopener" target="_blank" title="https://github.com/Elgg/Elgg/blob/1.x/engine/classes/Elgg/Di/ServiceProvider.php#L14"&gt;https://github.com/Elgg/Elg...&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mrclay</dc:creator><pubDate>Fri, 20 Mar 2015 13:14:34 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918402265</link><description>&lt;p&gt;While I agree, there are large applications not easily refactorable to remove all storage logic from entities. A service locator is better than nothing. (but agreed this is worse that SL)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mrclay</dc:creator><pubDate>Fri, 20 Mar 2015 13:10:34 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918396729</link><description>&lt;p&gt;A step above this would be to use a service locator that can at least give you documented types by using (faux) properties/methods. E.g. See &lt;a href="https://github.com/mrclay/Props" rel="nofollow noopener" target="_blank" title="https://github.com/mrclay/Props"&gt;https://github.com/mrclay/P...&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Ideally you'd use a capable DIC like PHP-DI that uses reflection to auto-assemble the dependencies you need when it constructs the object.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">mrclay</dc:creator><pubDate>Fri, 20 Mar 2015 13:07:25 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>https://jasonlotito.silvrback.com/programming/injectors-dependency-injection-with-traits/#comment-1918320904</link><description>&lt;p&gt;This isn't dependency injection. It's service location of the worst kind. Your User does not need ANY those services inside of it, especially not hidden behind static service location. You should have services that operate on the user, Ex: $mailer-&amp;gt;sendRegistrationEmail($user), $session-&amp;gt;cache($user), $tracker-&amp;gt;track($user). Shoving your entire application inside of your entities is going to become a big ball of mud very quickly.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">David Adams</dc:creator><pubDate>Fri, 20 Mar 2015 12:24:02 -0000</pubDate></item><item><title>Re: What I know about designing credit card forms</title><link>https://jasonlotito.silvrback.com/programming/what-i-know-about-designing-credit-card-forms#comment-1141143335</link><description>&lt;p&gt;Great post, Jason! As always, I enjoy reading your article man. Keep it up!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Vitaliy</dc:creator><pubDate>Wed, 27 Nov 2013 09:13:55 -0000</pubDate></item><item><title>Re: How to get an invite to Forrst</title><link>http://www.jasonlotito.com/programming/how-to-get-an-invite-to-forrst/#comment-1039960685</link><description>&lt;p&gt;I'd appreciate it if a Forrst member would take a look into my developer application! &lt;a href="http://forrst.com/i/e7WQ" rel="nofollow noopener" target="_blank" title="http://forrst.com/i/e7WQ"&gt;http://forrst.com/i/e7WQ&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Clara</dc:creator><pubDate>Thu, 12 Sep 2013 05:33:38 -0000</pubDate></item><item><title>Re: How to get an invite to Forrst</title><link>http://www.jasonlotito.com/programming/how-to-get-an-invite-to-forrst/#comment-907628684</link><description>&lt;p&gt;Hey Jason, I have been waiting and waiting for my application to get votes. Would you be able to help me out? Your article was very helpful as well. Thanks :)&lt;/p&gt;&lt;p&gt;&lt;a href="http://forrst.com/i/iXvK" rel="nofollow noopener" target="_blank" title="http://forrst.com/i/iXvK"&gt;http://forrst.com/i/iXvK&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Isaac</dc:creator><pubDate>Fri, 24 May 2013 23:43:11 -0000</pubDate></item><item><title>Re: How to get an invite to Forrst</title><link>http://www.jasonlotito.com/programming/how-to-get-an-invite-to-forrst/#comment-806359668</link><description>&lt;p&gt;Please invite me &lt;a href="http://inews24h.com" rel="nofollow noopener" target="_blank" title="inews24h.com"&gt;inews24h.com&lt;/a&gt;@gmail.com &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tina Swift</dc:creator><pubDate>Wed, 20 Feb 2013 20:44:38 -0000</pubDate></item><item><title>Re: 3, good, white noise sites</title><link>http://www.jasonlotito.com/life-hacking/3-good-white-noise-sites/#comment-746775289</link><description>&lt;p&gt;Thank you so much for this compiled list. I use Rainymood all the time when I have to get schoolwork done. I can't wait to check out the other sites -ocean waves seem quite tempting! &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">kendra</dc:creator><pubDate>Mon, 24 Dec 2012 06:02:44 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>http://www.jasonlotito.com/programming/injectors-dependency-injection-with-traits/#comment-738630631</link><description>&lt;p&gt;I really like your approach because of the following:&lt;br&gt;- All dependencies are clearly visible from the class constructor.&lt;br&gt;- Specification of phpdoc return type to allow for auto-completion.&lt;br&gt;- The injector seems like a good place for additional service bootstrapping.&lt;br&gt;- It's a great use of traits (of which I haven't seen many good examples)&lt;/p&gt;&lt;p&gt;I just wanted to point out what I perceive as a major difference between this method and proper DI/IoC. To many experts, DI/IoC implies constructing the whole (service) object graph in one go, before the control flow of the application starts. &lt;/p&gt;&lt;p&gt;I'm interested to hear about the problems you ran into with your approach, if you find the time to elaborate! For example, I don't see how you could inject dependencies which have other dependencies. I imagine running into serious problems when using another injector trait inside of an injector trait..&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Adrian Imfeld</dc:creator><pubDate>Sun, 16 Dec 2012 05:42:07 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>http://www.jasonlotito.com/programming/injectors-dependency-injection-with-traits/#comment-737639138</link><description>&lt;p&gt;I understand what you are saying, but I think there are subtle difference between this method and Service Locator.  The DiC is actually not important.  The traits, in essence, can return anything however they want.  That they happen to us a Service Locator in this case is unimportant.&lt;/p&gt;&lt;p&gt;Also, because of the way traits are setup in classes, they are clearly defined in the interface.  This, of course, assumes are you using a common pattern, which in my case is injectors.  Regardless, it creates that clear interface (avoiding one of the problems presented by service locators).&lt;/p&gt;&lt;p&gt;The final difference between this method and service locators is that with SL, it's difficult to follow the code and see what's actually happening.  With traits, it's not.  Quite the reverse.&lt;/p&gt;&lt;p&gt;I should note that I've continued to move forward from this.&lt;/p&gt;&lt;p&gt;I have problems with this method, but not the same problem I have with a service locator.  Regardless, it's a pattern I continue to explore.&lt;/p&gt;&lt;p&gt;Thanks for the additional reading.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jason Lotito</dc:creator><pubDate>Sat, 15 Dec 2012 14:03:51 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>http://www.jasonlotito.com/programming/injectors-dependency-injection-with-traits/#comment-737457737</link><description>&lt;p&gt;It seems to me that you're using Service Location (in an elegant way!) here, not Dependency Injection. Proper Dependency Injection implies constructing the whole object graph from scratch outside of the application’s control flow and injecting objects using the DiC as an *external agent*. The DiC should not be used inside the classes as you use it in your injector traits. Here are some relevant resources:&lt;/p&gt;&lt;p&gt;- &lt;a href="http://blog.astrumfutura.com/2011/10/zend-framework-2-0-dependency-injection-part-2/" rel="nofollow noopener" target="_blank" title="http://blog.astrumfutura.com/2011/10/zend-framework-2-0-dependency-injection-part-2/"&gt;http://blog.astrumfutura.co...&lt;/a&gt;&lt;br&gt;- &lt;a href="http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx" rel="nofollow noopener" target="_blank" title="http://blog.ploeh.dk/2010/02/03/ServiceLocatorIsAnAntiPattern.aspx"&gt;http://blog.ploeh.dk/2010/0...&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Adrian Imfeld</dc:creator><pubDate>Sat, 15 Dec 2012 11:08:15 -0000</pubDate></item><item><title>Re: How to get an invite to Forrst</title><link>http://www.jasonlotito.com/programming/how-to-get-an-invite-to-forrst/#comment-643959100</link><description>&lt;p&gt;Hey forrst peeps, I'd love to help out and contribute to the community. A vote for me is a virtual high five for you!&lt;/p&gt;&lt;p&gt;&lt;a href="http://forrst.com/i/og4" rel="nofollow noopener" target="_blank" title="http://forrst.com/i/og4"&gt;http://forrst.com/i/og4&lt;/a&gt;&lt;/p&gt;&lt;p&gt;:)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Curt</dc:creator><pubDate>Sat, 08 Sep 2012 00:52:08 -0000</pubDate></item><item><title>Re: How to get an invite to Forrst</title><link>http://www.jasonlotito.com/programming/how-to-get-an-invite-to-forrst/#comment-623785491</link><description>&lt;p&gt;Can I get 2 votes too &lt;a href="http://forrst.com/i/nTm" rel="nofollow noopener" target="_blank" title="http://forrst.com/i/nTm"&gt;http://forrst.com/i/nTm&lt;/a&gt;&lt;/p&gt;&lt;p&gt;When you feel I deserve it, please give it to me, &lt;/p&gt;&lt;p&gt;I will return the favor.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Aziz Ali</dc:creator><pubDate>Mon, 20 Aug 2012 01:55:17 -0000</pubDate></item><item><title>Re: How to get an invite to Forrst</title><link>http://www.jasonlotito.com/programming/how-to-get-an-invite-to-forrst/#comment-614832183</link><description>&lt;p&gt;&lt;a href="http://forrst.com/i/FTx" rel="nofollow noopener" target="_blank" title="http://forrst.com/i/FTx"&gt;http://forrst.com/i/FTx&lt;/a&gt; &lt;br&gt;Pls vote I'd really appreciate it if you vote :)&lt;br&gt;I will take me graphic design course in this year , but I do some works sometimes since 5 years ago &lt;br&gt;&lt;a href="http://www.tumblr.com/blog/alexandrelagem" rel="nofollow noopener" target="_blank" title="http://www.tumblr.com/blog/alexandrelagem"&gt;http://www.tumblr.com/blog/...&lt;/a&gt;&lt;br&gt;&lt;a href="http://alexandrelagem.blogspot.pt/" rel="nofollow noopener" target="_blank" title="http://alexandrelagem.blogspot.pt/"&gt;http://alexandrelagem.blogs...&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alexarl15</dc:creator><pubDate>Thu, 09 Aug 2012 16:24:55 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>http://www.jasonlotito.com/programming/injectors-dependency-injection-with-traits/#comment-593457859</link><description>&lt;p&gt;Yeah, so as you said, you could just inject it into the Container for the test.  You can also create Injectors for your Tests and include them over your normal injectors.&lt;/p&gt;&lt;p&gt;Either way works fine for testing purposes.  That was one of the things I wanted to spell out in the article, but it had been sitting around so long, I figured I'd get the idea out.&lt;/p&gt;&lt;p&gt;Anyways, it's still testable, whether you use a Container or not. &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jason Lotito</dc:creator><pubDate>Fri, 20 Jul 2012 14:24:08 -0000</pubDate></item><item><title>Re: Injectors: Dependency Injection with Traits</title><link>http://www.jasonlotito.com/programming/injectors-dependency-injection-with-traits/#comment-593213835</link><description>&lt;p&gt;So how would you go about testing that User class? I don't see how would you mock the config in this case, since your injector is actually hardcoded in the use statement and you cannot substitute it.&lt;/p&gt;&lt;p&gt;On the second thought it seems you're using it as a substitute for internal accessor that are common when you have DI style code without DIC:&lt;br&gt;protected function _db() {   if (!isset($this-&amp;gt;_db)) $this-&amp;gt;_db = new Db;&lt;br&gt;   return $this-&amp;gt;_db;}public function __construct($db = null) {   $this-&amp;gt;_db = $db;}public function someMethod() {   $record = $this-&amp;gt;_db()-&amp;gt;query("...")-&amp;gt;fetchOne();   // ...}&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Bruce Weirdan</dc:creator><pubDate>Fri, 20 Jul 2012 10:18:20 -0000</pubDate></item><item><title>Re: How to get an invite to Forrst</title><link>http://www.jasonlotito.com/programming/how-to-get-an-invite-to-forrst/#comment-589214835</link><description>&lt;p&gt;I am a Wordpress developer and i like to join on Forrst can any one please vote me &lt;a href="http://forrst.com/i/JjD" rel="nofollow noopener" target="_blank" title="http://forrst.com/i/JjD"&gt;http://forrst.com/i/JjD&lt;/a&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Maidul</dc:creator><pubDate>Mon, 16 Jul 2012 09:43:10 -0000</pubDate></item></channel></rss>