Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>IoC frameworks are excellent if you want to...</p> <ul> <li><p>...throw away type safety. Many (all?) IoC frameworks forces you to execute the code if you want to be certain everything is hooked up correctly. "Hey! Hope I got everything set up so my initializations of these 100 classes won't fail in production, throwing null-pointer exceptions!"</p></li> <li><p>...litter your code with globals (IoC frameworks are <em>all</em> about changing global states).</p></li> <li><p>...write crappy code with unclear dependencies that's hard to refactor since you'll never know what depends on what.</p></li> </ul> <p>The problem with IoC is that the people who uses them used to write code like this</p> <pre><code>public class Foo { public Bar Apa {get;set;} Foo() { Apa = new Bar(); } } </code></pre> <p>which is obviously flawed since the dependency between Foo and Bar is hard-wired. Then they realized it would be better to write code like</p> <pre><code>public class Foo { public IBar Apa {get;set;} Foo() { Apa = IoC&lt;IBar&gt;(); } } </code></pre> <p>which is also flawed, but less obviously so. In Haskell the type of <code>Foo()</code> would be <code>IO Foo</code> but you really don't want the <code>IO</code>-part and is should be a warning sign that something is wrong with your design if you got it.</p> <p>To get rid of it (the IO-part), get all advantages of IoC-frameworks and none of it's drawbacks you could instead use an abstract factory.</p> <p>The correct solution would be something like</p> <pre><code>data Foo = Foo { apa :: Bar } </code></pre> <p>or maybe</p> <pre><code>data Foo = forall b. (IBar b) =&gt; Foo { apa :: b } </code></pre> <p>and inject (but I wouldn't call it inject) Bar.</p> <p>Also: see this video with Erik Meijer (inventor of LINQ) where he says that DI is for people who don't know math (and I couldn't agree more): <a href="http://www.youtube.com/watch?v=8Mttjyf-8P4" rel="noreferrer">http://www.youtube.com/watch?v=8Mttjyf-8P4</a></p> <p>Unlike Mr. Spolsky I don't believe that people who use IoC-frameworks are very smart - I simply believe they don't know math.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload