Dependency Injection – Keep your privates to yourself

Jacob Proffitt has hit the nail on the head with his “I do wish that people would admit that DI doesn’t have compelling applicability outside of Unit Testing” post, the discussion continues with Nate Kohari response post and Jacobs counter post. Oren has also joined in with two posts.

Here a some ideas for you to think about.

DI as a Silver Bullet – You lose power

When you use DI as a ‘Silver Bullet’ you are losing more then half the abilities of your programming language. You can not use static methods or the ‘new‘ keyword or sealed types. Oh, you have to make all your methods virtual too. This is going to be even harder once Extension Methods (and Linq) become main stream.

Code to Enable Change – Costs More

Creating Code that is there only to “Enable Change” has a big “YAGNI” written all over it. (Making the code more complex and thus wasting time in development and then in maintenance, for a chance that it will be used in the future). We have understood that this is the wrong plan ages ago. We now know that we can not predict the future and it is best to change our code only when we need to (a process called refactoring).

Keep your Privates to Yourself

Jacob, you are quite right about DI coming into fashion only because the tools where not good enough. DI does have other applications outside testing, but it is being overused in most application only to make the code testable.

One of the first issues that was discussed when TDD was starting was: “should we change our code to make it testable?”
Should we change the visibility of our code?
Should we change the design of our code?
This lead to a collision between testable code and OO encapsulation. Developers started to expose private parts of the code to enable testing. It started with private fields and methods and now it is the complete design. This collision still exists when using inadequate tools, but with the right tools, you can enjoy the best of both worlds.

Get the Best Tools to get the Job Done

Thousands of developers have understood this and have started testing there code without being forced to use a specific pattern required by some tools. Many development shops, didn’t test their code because of the testability/design collision. With the right tools they now understand and test their code.

As Joel Says: “Get the best tools

417 comments
  1. You really make it appear so easy together with your presentation however I in finding this matter to be really something which I feel I would by no means understand.
    It seems too complicated and very wide for me. I’m taking a look ahead to your subsequent post,
    I will attempt to get the cling of it!

  2. Great goods from you, man. I have take not your stuff
    previous to and you’re just too great. I actually like what you have receioved right here, really like what you’re stating
    and the way in which in which you assert it. You are making it
    entertaining and you still take care of to keep it
    wise. I cant wait to learn much more from you.
    That is really a terrific site.

  3. For example, I inspired one despondent consumer, with a very tight adveertising finances, to get together
    together with his fellow retailers in a neighborhood mall to dischss the possibility
    of launching a marketing budget template 2015 (vihowowu.bandcamp.Com) marketing campoaign that they
    might all profit from with tthe additional good thing
    abouit with the ability to shnare the whole cost.

  4. The fact is: Regardless of a full-sized sport utility vehicle CUV comes in and of your financial consideration. The main benefit of
    an individual or the company is already being snapped up in the
    Florida lemon law. You should be based on a specific customer in mind that automobile new most anticipated cars of 2017 (http://projects.adityainfo.co.in/) it tends
    to look at. Side and curtain airbags are now normal across the Pajero variety, combining stability control, grip
    control, power, seating capacity etc. It is necessary to have the standard
    features.

  5. It also can be used as a anti snatch personal alarm that when a purse is taken from a woman a pin is
    pulled out and the alarm sounds loudly and a light flashes startling the intruder who normally would drop the device and purse rather than rather than to call attention to himself.
    No worries though, as you are still able to get the tax credit.
    pepper sprays could be used in the same way and located in different areas of the home for the same protection purpose.

  6. Each phrase, preferably containing two to three optimizers words, how to search about various topics.
    suchmaschinenoptimierung google kostenlos – Christie – has a solid approach into
    what is needed closer to his visions.

  7. Hey there just wanted to give you a quick heads up. The text
    in your post seem to be not viewable on the screen in Chrome.

    I’m not sure if this is a format issue or something to do with browser
    compatibility but I thought I’d post to let you know. The design and style look great though!
    Hope you get the issue solved soon. Kudos

Add Comment

Required fields are marked *. Your email address will not be published.