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)

    One of the benefits of a college education is, to show the boy its little avail.
    Ralph Waldo Emerson (1803–1882)

    It is with benefits as with injuries in this respect, that we do not so much weigh the accidental good or evil they do us, as that which they were designed to do us.—That is, we consider no part of them so much as their intention.
    Laurence Sterne (1713–1768)