Click here to Skip to main content
15,904,351 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Dependency Injection/IoC Pin
kdmote11-Oct-18 9:21
kdmote11-Oct-18 9:21 
GeneralRe: Dependency Injection/IoC Pin
RickZeeland10-Oct-18 6:29
mveRickZeeland10-Oct-18 6:29 
GeneralRe: Dependency Injection/IoC Pin
Slacker00710-Oct-18 8:05
professionalSlacker00710-Oct-18 8:05 
GeneralRe: Dependency Injection/IoC Pin
Marco Bertschi10-Oct-18 8:37
protectorMarco Bertschi10-Oct-18 8:37 
GeneralRe: Dependency Injection/IoC Pin
Slacker00710-Oct-18 8:57
professionalSlacker00710-Oct-18 8:57 
GeneralRe: Dependency Injection/IoC Pin
TNCaver11-Oct-18 4:04
TNCaver11-Oct-18 4:04 
GeneralRe: Dependency Injection/IoC PinPopular
Sander Rossel10-Oct-18 8:37
professionalSander Rossel10-Oct-18 8:37 
GeneralRe: Dependency Injection/IoC Pin
Marc Clifton10-Oct-18 9:10
mvaMarc Clifton10-Oct-18 9:10 
TNCaver wrote:
code that uses an external object still has to know about it's properties and methods in order to use them, so how does passing the object or interface to the constructor or a setter make the code any less dependent than using the concrete object with the 'new' keyword?


Imagine a door. On that door is a knocker. Imagine another door. On the side of that door is a doorbell. Imagine an interface. The interface has one method: "Announce" -- Announce someone is waiting at the door."

Now go knock on the door or ring the doorbell. They both implement "Announce". I think I'll stop now about injecting knockers.

TNCaver wrote:
I'm learning about DI, and it kind of makes sense, but I'm not convinced it solves the loose coupling issue.


It does, if you don't abuse it. And boy, have I seen abuse. However, I avoid DI like the plague because it flips the problem on its head. Most DI's that I've seen basically express in metadata (XML, JSON, whatever):

Property-of-instance-Foo-gets-initialized-with-interface-Eye.

And worse, some of those DI's will instantiate Foo for you if it doesn't exist at the point in time of the injection. Massive entanglement of dependencies ensues -- what if the instance of Foo is itself a dependency?

Now, you also have another choice. Foo itself can implement an interface that defines the property (of some interface type) that the DI is told about and can set. That's pretty quick. Otherwise, the DI has to rely on reflection to set the property of Foo, because it doesn't know what type it is and has no interface to map Foo's property to a "known" interface. Reflection is slow.

Now magnify that problem with hundreds, if not thousands, of entangled dependencies, all specified in some XML file (yes, I've actually seen this) and you get a nightmare that is impossible to debug, slow to instantiate, and brittle to changes.

I'm old fashioned. Give me a factory pattern. DI is a bad solution looking for an already solved problem.
Latest Article - A Concise Overview of Threads

Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

Artificial intelligence is the only remedy for natural stupidity. - CDP1802

GeneralRe: Dependency Injection/IoC Pin
Slacker00710-Oct-18 9:42
professionalSlacker00710-Oct-18 9:42 
GeneralRe: Dependency Injection/IoC Pin
Marc Clifton11-Oct-18 4:01
mvaMarc Clifton11-Oct-18 4:01 
GeneralRe: Dependency Injection/IoC Pin
TNCaver11-Oct-18 4:07
TNCaver11-Oct-18 4:07 
GeneralRe: Dependency Injection/IoC Pin
TNCaver11-Oct-18 4:09
TNCaver11-Oct-18 4:09 
GeneralRe: Dependency Injection/IoC Pin
Slacker00711-Oct-18 5:44
professionalSlacker00711-Oct-18 5:44 
GeneralRe: Dependency Injection/IoC Pin
Jon McKee10-Oct-18 10:26
professionalJon McKee10-Oct-18 10:26 
GeneralRe: Dependency Injection/IoC Pin
Matthew Dennis10-Oct-18 12:30
sysadminMatthew Dennis10-Oct-18 12:30 
GeneralRe: Dependency Injection/IoC Pin
GuyThiebaut10-Oct-18 20:35
professionalGuyThiebaut10-Oct-18 20:35 
GeneralRe: Dependency Injection/IoC Pin
englebart11-Oct-18 4:33
professionalenglebart11-Oct-18 4:33 
GeneralRe: Dependency Injection/IoC Pin
Steve Naidamast11-Oct-18 5:46
professionalSteve Naidamast11-Oct-18 5:46 
GeneralRe: Dependency Injection/IoC Pin
RandyBuchholz12-Oct-18 12:34
RandyBuchholz12-Oct-18 12:34 
GeneralThought of the Day Pin
OriginalGriff10-Oct-18 5:00
mveOriginalGriff10-Oct-18 5:00 
GeneralRe: Thought of the Day Pin
Johnny J.10-Oct-18 5:05
professionalJohnny J.10-Oct-18 5:05 
GeneralRe: Thought of the Day Pin
W Balboos, GHB10-Oct-18 5:21
W Balboos, GHB10-Oct-18 5:21 
GeneralRe: Thought of the Day Pin
megaadam10-Oct-18 5:32
professionalmegaadam10-Oct-18 5:32 
GeneralRe: Thought of the Day Pin
PIEBALDconsult10-Oct-18 5:35
mvePIEBALDconsult10-Oct-18 5:35 
GeneralRe: Thought of the Day Pin
DRHuff10-Oct-18 7:49
DRHuff10-Oct-18 7:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.