Dependency Injection - Benefits

Benefits

One benefit of using the dependency injection approach is the reduction of boilerplate code in the application objects since all work to initialize or set up dependencies is handled by a provider component.

Another benefit is that it offers configuration flexibility because alternative implementations of a given service can be used without recompiling code. This is useful in unit testing, as it is easy to inject a fake implementation of a service into the object being tested by changing the configuration file, or overriding component registrations at run-time.

Furthermore, dependency injection facilitates the writing of testable code.

Read more about this topic:  Dependency Injection

Famous quotes containing the word benefits:

    In America the young are always ready to give to those who are older than themselves the full benefits of their inexperience.
    Oscar Wilde (1854–1900)

    I do seriously believe that if we can measure among the States the benefits resulting from the preservation of the Union, the rebellious States have the larger share. It destroyed an institution that was their destruction. It opened the way for a commercial life that, if they will only embrace it and face the light, means to them a development that shall rival the best attainments of the greatest of our States.
    Benjamin Harrison (1833–1901)

    While greedy good-doers, beneficent beasts of prey,
    Swarm over their lives enforcing benefits ...
    Robert Frost (1874–1963)