0% found this document useful (0 votes)
47 views3 pages

Motivation For Dependency Injection

The document discusses the motivation for using dependency injection for large scale software projects. It cites benefits like improved maintainability and loose coupling between classes, better testability by isolating tests, extensibility by allowing new object types without code changes, and enabling parallel development. Dependency injection removes direct dependencies between classes by introducing interfaces and allowing an injecting container to manage dependencies. While it adds complexity, the approach improves code organization, flexibility, and ability to reconfigure the system.

Uploaded by

Nickleus Jimenez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views3 pages

Motivation For Dependency Injection

The document discusses the motivation for using dependency injection for large scale software projects. It cites benefits like improved maintainability and loose coupling between classes, better testability by isolating tests, extensibility by allowing new object types without code changes, and enabling parallel development. Dependency injection removes direct dependencies between classes by introducing interfaces and allowing an injecting container to manage dependencies. While it adds complexity, the approach improves code organization, flexibility, and ability to reconfigure the system.

Uploaded by

Nickleus Jimenez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Motivation For Dependency Injection

Nickleus Jimenez
Software Engineer
Philippines

The following cites benefits of using dependency injection for large scale software projects

Keywords: Software Engineering; Dependency Injection;

1 Introduction
Dependency injection removes the dependence of class a on class by adding a container and making it
responsible for the dependency look up. The result when following the technique is decoupling the usage
of an object from its creation. The technique involves using interfaces to break the dependencies between
higher and lower level classes. As a result, both classes depend on the interface and no longer on each
other.

Applying dependency injection is an added layer of work for functionalities but there are reasons why
such effort can be worthwhile. The reasons cited by Betss et al.(2013) Those reasons mentioned are
Maintainability, testability, extensibility, late binding, parallel development and crosscutting concerns

2 Maintainability and loose coupling


Maintaining systems get more challenging as they get larger. The large scale may make it difficult for
quick changes without unintended consequences. Dependency injection contribute in maintainability if
classes are loosely coupled and follow single responsibility. Maintainability improves because both classes
depend on the interface and not each other making it possible to change implementation of class B without
affecting class A.

3 Testability
The interfaces makes it possible to isolate tests to a certain method of a class since other classes are
injected with mock results so setting up the values for the method to be tested is possible. Depending on
interfaces enables testing individual parts of the system.

4 Extensibility
Systems that are designed using interfaces can be extended by adding new kinds of objects that implement
the interface without requiring any changes to existing code. Hence, Dependency injection’s use of
interfaces provides extensibility. The practice makes the system work in different ways or add features as
requirements changes.

Developer Commentary, Nickleus (2021) for public reading


2 Dependency Injection

5 Late Binding
Primary usefulness of late binding is the ability to replace part of your system without recompiling.
Executing dependency injection with xml or json config makes it possible for changing to another imple-
mentation when the need arises like when the database change from one kind of sql to another without
recompiling. Architecture that benefit the most from this is the plug-in architecture.

6 Parallel development
It’s not practical in large project to have the entire development team work simultaneously on the same
component or feature. Having the dev teams configure the dependency to use mock implementations
for classes that are being currently worked on by others makes it possible for them to focus on their
assigned components to implement. after that, others can reconfigure when they receive the completed
implementation.

7 Crosscutting Concerns
Cross-cutting concerns are parts of a system that rely on or must affect many other parts of the system.
Examples include logging, exception handling and validation. These features may be needed in many
different areas of the application. It is desirable that those features be implemented in a standard and
consistent way. When situation changes, reconfiguration for different set of implementations of those cross
cutting concerns can be done. Of course those have to be implemented but the contract from interfaces
will tell the developers what needs to be done.

A Advantages and Disadvantages


Here are the pros and cons of using dependency injection. The benefits cited earlier already makes the
practice or pattern in Microsoft’s terms worthwhile for large software systems that has to be maintained.

Developer Commentary, Nickleus (2021)


Benefits of Dependency Injection 3

Advantages Disadvantages
Allows a client application the flexibility of being Creates clients that require configuration details pro-
configurable. Only the client’s behavior is fixed. The vided by construction code which may onerous when
client may act on anything that supports the intrin- obvious defaults are available
sic interface the client expects or needs
Externalize a system’s configuration details into con- Makes code difficult to trace (read) without debug-
figuration files, allowing the system to be reconfig- ging because behavior is separated from construction
ured without recompilation. Separate configurations
can be used for different scenarios that require differ-
ent implementations of components. One example is
testing.
Does not require any change in code behavior it can developers must refer to more files to follow how a
be applied to legacy code as a refactoring. system performs
Isolate the client from the impact of design changes Usually requires more upfront development effort
and defects by removing all knowledge of a concrete since one can not summon into being something right
implementation that needed. when and where it is needed but must ask that it be
injected and then ensure that it has been injected.
Two developers can independently develop classes Forces complexity to move out of classes and into the
that use each other, while only needing to know the linkages between classes
interface the classes to be implemented or injected.

References
[1] Betts, D., Melnik, G., Simonazzi, F., Subramanian, M., and Tavares, C. (2013). Dependency Injection with
Unity. Microsoft Patterns Practices.

Developer Commentary, Nickleus (2021)

You might also like