What is dependency injection

396 viewsOtherTechnology

What is dependency injection

In: Technology

6 Answers

Anonymous 0 Comments

Most programming is pretty linear — when you call a function, you pass in what the function needs. If a function takes parameters X, Y, and Z, you provide those.

With dependency injection you flip this on its head. First you declares somewhere, “hey if you need an X, I’m how you get it”. Similarly for Y and Z. Then when the function is called, you don’t give it anything — instead, it knows it needs an X, and it looks in the registered providers for how to get one. Then it gets it.

It’s basically a way to turn nice predictable flows into a horrible rat’s nest of untraceable dependencies which are impossible to debug sensibly.

You are viewing 1 out of 6 answers, click here to view all answers.