Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does dependency injection require another language?

I'm comfortable programming in Java, but am fairly new to Spring. I've been reading about dependency-injection/inversion of control (and using it with Spring for the past few months), but I can't figure out the need for a separate language (xml/spring) to accomplish it.

What is wrong with creating a singleton in Java called DependencyHandler, and keeping everything in the same language? What are the advantages I get by using xml/Spring?

like image 228
Cory Kendall Avatar asked Oct 26 '11 05:10

Cory Kendall


People also ask

What does dependency injection require?

A form of inversion of control, dependency injection aims to separate the concerns of constructing objects and using them, leading to loosely coupled programs. The pattern ensures that an object or function which wants to use a given service should not have to know how to construct those services.

What is dependency injection in a programming language?

In object-oriented programming (OOP) software design, dependency injection (DI) is the process of supplying a resource that a given piece of code requires. The required resource, which is often a component of the application itself, is called a dependency.

Why do we need dependency injection in Javascript?

Dependency Injection (or DI for short) is a way of constructing your application so that you are not creating dependencies locally, but instead are being provided those dependencies from somewhere else in your application.

Is dependency injection needed in Python?

Python is an interpreted language with dynamic typing. There is an opinion that dependency injection doesn't work for it as well as it does for Java. A lot of the flexibility is already built-in. Also, there is an opinion that a dependency injection framework is something that Python developer rarely needs.


1 Answers

Dependency Injection does not require a separate language.

Spring is a framework for Java that historically required configuration in xml. Now you can configure it using xml, or java annotations.

Google's Guice is a simple dependency injection framework that has all configuration in Java.

like image 68
digitaljoel Avatar answered Sep 30 '22 08:09

digitaljoel