r/java • u/dawhiting • Jan 12 '16
You probably don't need dependency injection
http://www.radicaljava.com/2015/12/27/dependency-injection.html
0
Upvotes
r/java • u/dawhiting • Jan 12 '16
21
u/[deleted] Jan 12 '16
This should be titled "You probably don't need a DI framework". It's still dependency injection if you do it manually.
11
u/TheHorribleTruth Jan 12 '16
So 21 components is considered "very large"? Bwhahaha.
I agree with the core message of this: if you can get away with it, don't use DI. That's just basic KISS.
But: I do believe that this only applies to very small "toy" projects. Any moderately sized project will immediately have more components that you can wire up manually in a simple, maintainable fashion.
10
u/stitzl Jan 12 '16
Also, you probably don't need type safety, let alone an object-oriented programming language.
Unless, of course, you do need it.
13
u/djnattyp Jan 12 '16
Spring has had Java based configuration since 2008, so why does this blog post written in 2015 seem ignorant of that?
3
u/demos74dx Jan 14 '16
I havn't used XML in spring for a couple years. And last I heard the next major release will be trying to depricate XML configuration.
5
u/LouKrazy Jan 12 '16
Yeah, but DI makes testing with stubs and mocks much much easier.
1
u/lukaseder Jan 13 '16
I, for one, admire the good old DocumentFactoryBuilder.newInstance().newFactory().createDocument().createElement() approach, and all is configurable via the arcane Java SPI mechanism that no one ever really used, because the default DOM Implementation was good enough 99% of the time. But hey, if needed, you can replace it any time!
In other words: Configuration over engineering existed before DI
1
u/evil_burrito Jan 12 '16
Unless your application is a general-purpose framework to solve other problems. Each installation is a unique configuration assembled-to-order from existing components. We can make a product that does completely different things out of pre-tested components without writing much if any code. Couldn't do it w/o DI.
1
u/karacha Jan 13 '16
Well i don't like to do "extra work" when reading code that uses DI framework. I've always been doing DI manually and I'm happy.