Why does dependency injection require a different language?

I find it more convenient to program in Java, but I'm pretty new to Spring. I read about dependency management / inversion management (and using it with Spring for the past few months), but I cannot understand the need for a separate language (xml / spring) to execute it.

What is wrong with creating a singleton in Java called DependencyHandler and saving all in one language? What benefits do I get with xml / Spring?

+5
source share
5 answers

Dependency injection does not require a separate language.

Spring - Java, xml. xml java-.

Google Guice - , Java.

+7

, ( xml) Java . DI, , , .

Spring , - , xml . Java-, xml. .

, . , , .

, - , .

+3

, Java. , Google Guice, .

+2

Spring - .

, factory :

public class Foo
{
    public Foo static mkFoo(/* dependencies */)
    {
        // assign dependencies to members
    }

    // ordinary class stuff
}

Foo.mkFoo(/*dependencies*/), Foo. spring.

Java DependencyHandler ?

. DI Java.

0

"" XML, .

, , , .

( , , ) , : / , , ..

Centralized configuration instead of the configuration scattered around the code base, it is in a group of files (or a single file). This is not only a virtuoso XML connection, it depends on how the settings are configured.

I think some configuration types are more suitable for external configuration. I choose based on what the reqs seem to meet, what the infrastructure allows, and how the structure handles configuration aspects.

0
source

All Articles