0% found this document useful (0 votes)
222 views

Dependency Injection

The document discusses dependency injection in software engineering. Dependency injection aims to separate the concerns of constructing objects and using them, leading to loosely coupled programs. It explains the roles involved, types of dependency injection, advantages and disadvantages, and provides examples of dependency injection versus without it.
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)
222 views

Dependency Injection

The document discusses dependency injection in software engineering. Dependency injection aims to separate the concerns of constructing objects and using them, leading to loosely coupled programs. It explains the roles involved, types of dependency injection, advantages and disadvantages, and provides examples of dependency injection versus without it.
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/ 57

Dependency

injection

In software engineering, dependency injection is a programming technique in which an


object or function receives other objects or functions that it requires, as opposed to creating
them internally. Dependency injection aims to separate the concerns of constructing objects
and using them, leading to loosely coupled programs.[1][2][3] The pattern ensures that an
object or function that wants to use a given service should not have to know how to construct
those services. Instead, the receiving 'client' (object or function) is provided with its
dependencies by external code (an 'injector'), which it is not aware of.[4] Dependency injection
makes implicit dependencies explicit and helps solve the following problems:[5]

How can a class be independent from


the creation of the objects it depends
on?
How can an application, and the
objects it uses support different
configurations?
Dependency injection is often used
alongside specialized frameworks,
known as 'containers', to facilitate
program composition.

Dependency injection is often used to keep code in-line with the dependency inversion
principle.[6][7]

In statically typed languages using dependency injection means a client only needs to declare
the interfaces of the services it uses, rather than their concrete implementations, making it
easier to change which services are used at runtime without recompiling.

Application frameworks often combine dependency injection with inversion of control. Under
inversion of control, the framework first constructs an object (such as a controller), and then
passes control flow to it. With dependency injection, the framework also instantiates the
dependencies declared by the application object (often in the constructor method's
parameters), and passes the dependencies into the object.[8]

Dependency injection implements the idea of "inverting control over the implementations of
dependencies," which is why certain Java frameworks generically name the concept
"inversion of control" (not to be confused with inversion of control flow).[9]

Roles
Dependency injection involves four roles: services, clients, interfaces and injectors.
Services and clients Dependency injection for
five-year-olds

When you go and get things


A service is any class which contains useful
out of the refrigerator for
functionality. In turn, a client is any class which uses
yourself, you can cause
services. The services that a client requires are the
problems. You might leave
client's dependencies.
the door open, you might

Any object can be a service or a client; the names relate get something Mommy or
only to the role the objects play in an injection. The Daddy don't want you to
same object may even be both a client (it uses injected have. You might even be

services) and a service (it is injected into other objects). looking for something we
Upon injection, the service is made part of the client's don't even have or which

state, available for use.[12] has expired.

What you should be doing is


stating a need, "I need
something to drink with

Interfaces
lunch," and then we will
make sure you have
something when you sit

Clients should not know how their dependencies are down to eat something.

implemented, only their names and API. A service which


John Munsch, 28 October
retrieves emails, for instance, may use the IMAP or
2009.[2][10][11]
POP3 protocols behind the scenes, but this detail is
likely irrelevant to calling code that merely wants an
email retrieved. By ignoring implementation details, clients do not need to change when their
dependencies do.

Injectors
The injector, sometimes also called an assembler, container, provider or factory, introduces
services to the client.
The role of injectors is to construct and connect complex object graphs, where objects may
be both clients and services. The injector itself may be many objects working together, but
must not be the client, as this would create a circular dependency.

Because dependency injection separates how objects are constructed from how they are
used, it often diminishes the importance of the new keyword found in most object-oriented
languages. Because the framework handles creating services, the programmer tends to only
directly construct value objects which represents entities in the program's domain (such as
an Employee object in a business app or an Order object in a shopping
app).[13][14][15][16]

Analogy
As an analogy, cars can be thought of as services which perform the useful work of
transporting people from one place to another. Car engines can require gas, diesel or
electricity, but this detail is unimportant to the client—a driver—who only cares if it can get
them to their destination.

Cars present a uniform interface through their pedals, steering wheels and other controls. As
such, which engine they were 'injected' with on the factory line ceases to matter and drivers
can switch between any kind of car as needed.

Advantages and
disadvantages

Advantages
A basic benefit of dependency injection is decreased coupling between classes and their
dependencies.[17][18]
By removing a client's knowledge of how its dependencies are implemented, programs
become more reusable, testable and maintainable.[19]

This also results in increased flexibility: a client may act on anything that supports the
intrinsic interface the client expects.[20]

More generally, dependency injection reduces boilerplate code, since all dependency creation
is handled by a singular component.[19]

Finally, dependency injection allows concurrent development. Two developers can


independently develop classes that use each other, while only needing to know the interface
the classes will communicate through. Plugins are often developed by third-parties that never
even talk to developers of the original product.[21]

Testing
Many of dependency injection's benefits are particularly relevant to unit-testing.

For example, dependency injection can be used to externalize a system's configuration details
into configuration files, allowing the system to be reconfigured without recompilation.
Separate configurations can be written for different situations that require different
implementations of components.[22]

Similarly, because dependency injection does not require any change in code behavior, it can
be applied to legacy code as a refactoring. This makes clients more independent and are
easier to unit test in isolation, using stubs or mock objects, that simulate other objects not
under test.

This ease of testing is often the first benefit noticed when using dependency injection.[23]

Disadvantages
Critics of dependency injection argue that it:
Creates clients that demand
configuration details, which can be
onerous when obvious defaults are
available.[21]
Makes code difficult to trace because
it separates behavior from
construction.[21]
Is typically implemented with reflection
or dynamic programming, hindering
IDE automation.[24]
Typically requires more upfront
development effort.[25]
Encourages dependence on a
framework.[26][27][28]
Types of dependency
injection
There are three main ways in which a client can receive injected services:[29]

Constructor injection, where


dependencies are provided through a
client's class constructor.
Setter injection, where the client
exposes a setter method which
accepts the dependency.
Interface injection, where the
dependency's interface provides an
injector method that will inject the
dependency into any client passed to
it.
In some frameworks, clients do not need to actively accept dependency injection at all. In
Java, for example, reflection can make private attributes public when testing and inject
services directly.[30]
Without dependency injection
In the following Java example, the Client class contains a Service member variable
initialized in the constructor. The client directly constructs and controls which service it uses,
creating a hard-coded dependency.

public class Client {


private Service
service;

Client() {
// The dependency
is hard-coded.
this.service = new
ExampleService();
}
}

Constructor injection
The most common form of dependency injection is for a class to request its dependencies
through its constructor. This ensures the client is always in a valid state, since it cannot be
instantiated without its necessary dependencies.
public class Client {
private Service
service;

// The dependency is
injected through a
constructor.
Client(Service
service) {
if (service ==
null) {
throw new
IllegalArgumentException("
service must not be
null");
}
this.service =
service;
}
}
Setter injection
By accepting dependencies through a setter method, rather than a constructor, clients can
allow injectors to manipulate their dependencies at any time. This offers flexibility, but makes
it difficult to ensure that all dependencies are injected and valid before the client is used.

public class Client {


private Service
service;

// The dependency is
injected through a setter
method.
public void
setService(Service
service) {
if (service ==
null) {
throw new
IllegalArgumentException("
service must not be
null");
}
this.service =
service;
}
}

Interface injection
With interface injection, dependencies are completely ignorant of their clients, yet still send
and receive references to new clients.

In this way, the dependencies become injectors. The key is that the injecting method is
provided through an interface.

An assembler is still needed to introduce the client and its dependencies. The assembler
takes a reference to the client, casts it to the setter interface that sets that dependency, and
passes it to that dependency object which in turn passes a reference to itself back to the
client.

For interface injection to have value, the dependency must do something in addition to simply
passing back a reference to itself. This could be acting as a factory or sub-assembler to
resolve other dependencies, thus abstracting some details from the main assembler. It could
be reference-counting so that the dependency knows how many clients are using it. If the
dependency maintains a collection of clients, it could later inject them all with a different
instance of itself.

public interface
ServiceSetter {
void
setService(Service
service);
}

public class Client


implements ServiceSetter {
private Service
service;

@Override
public void
setService(Service
service) {
if (service ==
null) {
throw new
IllegalArgumentException("
service must not be
null");
}
this.service =
service;
}
}
public class
ServiceInjector {
private final
Set<ServiceSetter> clients
= new HashSet<>();

public void
inject(ServiceSetter
client) {

this.clients.add(client);

client.setService(new
ExampleService());
}

public void switch() {


for (Client client
: this.clients) {

client.setService(new
AnotherExampleService());
}
}
}

public class
ExampleService implements
Service {}

public class
AnotherExampleService
implements Service {}

Assembly
The simplest way of implementing dependency injection is to manually arrange services and
clients, typically done at the program's root, where execution begins.

public class Program {

public static void


main(String[] args) {
// Build the
service.
Service service =
new ExampleService();

// Inject the
service into the client.
Client client =
new Client(service);

// Use the
objects.

System.out.println(client.
greet());
}
}

Manual construction may be more complex and involve builders, factories, or other
construction patterns.
Frameworks

Containers such as Ninject or


StructureMap are commonly used in
object-oriented programming
languages to achieve Dependency
Injection and inversion of control.

Manual dependency injection is often tedious and error-prone for larger projects, promoting
the use of frameworks which automate the process. Manual dependency injection becomes
a dependency injection framework once the constructing code is no longer custom to the
application and is instead universal.[31] While useful, these tools are not required in order to
perform dependency injection.[32][33]

Some frameworks, like Spring, can use external configuration files to plan program
composition:

import
org.springframework.beans.
factory.BeanFactory;
import
org.springframework.contex
t.ApplicationContext;
import
org.springframework.contex
t.support.ClassPathXmlAppl
icationContext;

public class Injector {

public static void


main(String[] args) {
// Details about
which concrete service to
use are stored in
configuration separate
from the program itself.
BeanFactory
beanfactory = new
ClassPathXmlApplicationCon
text("Beans.xml");
Client client =
(Client)
beanfactory.getBean("clien
t");

System.out.println(client.
greet());
}
}

Even with a potentially long and complex object graph, the only class mentioned in code is
the entry point, in this case Client . Client has not undergone any changes to work
with Spring and remains a POJO.[34][35][36] By keeping Spring-specific annotations and calls
from spreading out among many classes, the system stays only loosely dependent on
Spring.[27]

Examples

AngularJS
The following example shows an AngularJS component receiving a greeting service through
dependency injection.

function
SomeClass(greeter) {
this.greeter = greeter;
}

SomeClass.prototype.doSome
thing = function(name) {

this.greeter.greet(name);
}

Each AngularJS application contains a service locator responsible for the construction and
look-up of dependencies.

// Provide the wiring


information in a module
var myModule =
angular.module('myModule',
[]);

// Teach the injector how


to build a greeter
service.
// greeter is dependent on
the $window service.
myModule.factory('greeter'
, function($window) {
return {
greet: function(text)
{
$window.alert(text);
}
};
});

We can then create a new injector that provides components defined in the myModule
module, including the greeter service.

var injector =
angular.injector(['myModul
e', 'ng']);
var greeter =
injector.get('greeter');

To avoid the service locator antipattern, AngularJS allows declarative notation in HTML
templates which delegates creating components to the injector.

<div ng-
controller="MyController">
<button ng-
click="sayHello()">Hello</
button>
</div>

function
MyController($scope,
greeter) {
$scope.sayHello =
function() {
greeter.greet('Hello
World');
};
}

The ng-controller directive triggers the injector to create an instance of the controller
and its dependencies.

C#
This sample provides an example of constructor injection in C#.
using System;

namespace
DependencyInjection;

// Our client will only


know about this interface,
not which specific gamepad
it is using.
interface
IGamepadFunctionality {
string
GetGamepadName();
void
SetVibrationPower(float
power);
}

// The following services


provide concrete
implementations of the
above interface.

class XBoxGamepad :
IGamepadFunctionality {
float vibrationPower =
1.0f;

public string
GetGamepadName() => "Xbox
controller";

public void
SetVibrationPower(float
power) =>
this.vibrationPower =
Math.Clamp(power, 0.0f,
1.0f);
}

class PlaystationJoystick
: IGamepadFunctionality {
float vibratingPower =
100.0f;

public string
GetGamepadName() =>
"PlayStation controller";

public void
SetVibrationPower(float
power) =>
this.vibratingPower =
Math.Clamp(power * 100.0f,
0.0f, 100.0f);
}

class SteamController :
IGamepadFunctionality {
double vibrating =
1.0;

public string
GetGamepadName() => "Steam
controller";
public void
SetVibrationPower(float
power) => this.vibrating =
Convert.ToDouble(Math.Clam
p(power, 0.0f, 1.0f));
}

// This class is the


client which receives a
service.
class Gamepad {
IGamepadFunctionality
gamepadFunctionality;

// The service is
injected through the
constructor and stored in
the above field.
public
Gamepad(IGamepadFunctional
ity gamepadFunctionality)
=>
this.gamepadFunctionality
= gamepadFunctionality;

public void Showcase()


{
// The injected
service is used.
var gamepadName =
this.gamepadFunctionality.
GetGamepadName();
var message =
$"We're using the
{gamepadName} right now,
do you want to change the
vibrating power?";

Console.WriteLine(message)
;
}
}
class Program {
static void Main() {
var
steamController = new
SteamController();

// We could have
also passed in an
XboxController,
PlaystationJoystick, etc.
// The gamepad
doesn't know what it's
using and doesn't need to.
var gamepad = new
Gamepad(steamController);

gamepad.Showcase();
}
}
Go
Go does not support classes and usually dependency injection is either abstracted by a
dedicated library that utilizes reflection or generics (the latter being supported since Go 1.18
[37] [38]
). A simpler example without using dependency injection libraries is illustrated by the
following example of an MVC web application.

First, pass the necessary dependencies to a router and then from the router to the controllers:

package router

import (
"database/sql"
"net/http"

"example/controllers/users
"

"github.com/go-
chi/chi/v5"
"github.com/go-
chi/chi/v5/middleware"

"github.com/redis/go-
redis/v9"

"github.com/rs/zerolog"
)

type RoutingHandler struct


{
// passing the values
by pointer further down
the call stack
// means we won't
create a new copy, saving
memory
log *zerolog.Logger
db *sql.DB
cache *redis.Client
router chi.Router
}

// connection, logger and


cache initialized usually
in the main function
func NewRouter(
log *zerolog.Logger,
db *sql.DB,
cache *redis.Client,
) (r *RoutingHandler) {
rtr := chi.NewRouter()

return
&RoutingHandler{
log: log,
db: db,
cache: cache,
router: rtr,
}
}

func (r *RoutingHandler)
SetupUsersRoutes() {
uc :=
users.NewController(r.log,
r.db, r.cache)
r.router.Get("/users/:name
", func(w
http.ResponseWriter, r
*http.Request) {
uc.Get(w, r)
})
}

Then, you can access the private fields of the struct in any method that is it's pointer receiver,
without violating encapsulation.

package users

import (
"database/sql"
"net/http"

"example/models"

"github.com/go-
chi/chi/v5"
"github.com/redis/go-
redis/v9"

"github.com/rs/zerolog"
)

type Controller struct {


log
*zerolog.Logger
storage
models.UserStorage
cache *redis.Client
}

func NewController(log
*zerolog.Logger, db
*sql.DB, cache
*redis.Client) *Controller
{
return &Controller{
log: log,
storage:
models.NewUserStorage(db),
cache: cache,
}
}

func (uc *Controller)


Get(w http.ResponseWriter,
r *http.Request) {
// note that we can
also wrap logging in a
middleware, this is for
demonstration purposes

uc.log.Info().Msg("Getting
user")

userParam :=
chi.URLParam(r, "name")

var user *models.User


// get the user from
the cache
err :=
uc.cache.Get(r.Context(),
userParam).Scan(&user)
if err != nil {

uc.log.Error().Err(err).Ms
g("Error getting user from
cache. Retrieving from SQL
storage")
}

user, err =
uc.storage.Get(r.Context()
, "johndoe")
if err != nil {

uc.log.Error().Err(err).Ms
g("Error getting user from
SQL storage")
http.Error(w,
"Internal server error",
http.StatusInternalServerE
rror)
return
}
}

Finally you can use the database connection initialized in your main function at the data
access layer:

package models

import (
"database/sql"
"time"
)

type (
UserStorage struct {
conn *sql.DB
}

User struct {
Name string
`json:"name"
db:"name,primarykey"`
JoinedAt time.Time
`json:"joined_at"
db:"joined_at"`
Email string
`json:"email" db:"email"`
}
)

func NewUserStorage(conn
*sql.DB) *UserStorage {
return &UserStorage{
conn: conn,
}
}

func (us *UserStorage)


Get(name string) (user
*User, err error) {
// assuming 'name' is
a unique key
query := "SELECT *
FROM users WHERE name =
$1"

if err :=
us.conn.QueryRow(query,
name).Scan(&user); err !=
nil {
return nil, err
}

return user, nil


}

See also

Architecture description language


Factory pattern
Inversion of control
Plug-in (computing)
Strategy pattern
AngularJS
Service locator pattern
Parameter (computer programming)
Quaject

References

1. Seemann, Mark. "Dependency Injection is


Loose Coupling" (http://blog.ploeh.dk/201
0/04/07/DependencyInjectionisLooseCou
pling/) . blog.ploeh.dk. Retrieved
2015-07-28.

2. Seeman, Mark (October 2011).


Dependency Injection in .NET. Manning
Publications. p. 4. ISBN 9781935182504.
3. Niko Schwarz, Mircea Lungu, Oscar
Nierstrasz, “Seuss: Decoupling
responsibilities from static methods for
fine-grained configurability”, Journal of
Object Technology, Volume 11, no. 1 (April
2012), pp. 3:1-23

4. "HollywoodPrinciple" (http://c2.com/cgi/w
iki?HollywoodPrinciple) . c2.com.
Retrieved 2015-07-19.

5. "The Dependency Injection design pattern


- Problem, Solution, and Applicability" (htt
p://w3sdesign.com/?gr=u01&ugr=probl
e) . w3sDesign.com. Retrieved
2017-08-12.
6. Erez, Guy (2022-03-09). "Dependency
Inversion vs. Dependency Injection" (http
s://betterprogramming.pub/straightforwar
d-simple-dependency-inversion-vs-depend
ency-injection-7d8c0d0ed28e) . Medium.
Retrieved 2022-12-06.

7. Mathews, Sasha (2021-03-25). "You are


Simply Injecting a Dependency, Thinking
that You are Following the Dependency
Inversion…" (https://levelup.gitconnected.
com/you-are-simply-injecting-a-dependen
cy-thinking-that-you-are-following-the-dep
endency-inversion-32632954c208) .
Medium. Retrieved 2022-12-06.

8. "Spring IoC Container" (https://docs.sprin


g.io/spring-framework/docs/3.2.x/spring-
framework-reference/html/beans.html) .
Retrieved 2023-05-23.
9. Fowler, Martin. "Inversion of Control
Containers and the Dependency Injection
pattern" (https://martinfowler.com/article
s/injection.html#InversionOfControl) .
MartinFowler.com. Retrieved 4 June 2023.

10. "Dependency Injection in NET" (https://we


b.archive.org/web/20150721171646/htt
p://philkildea.co.uk/james/books/Depend
ency.Injection.in.NET.pdf) (PDF).
philkildea.co.uk. p. 4. Archived from the
original (http://philkildea.co.uk/james/bo
oks/Dependency.Injection.in.NET.pdf)
(PDF) on 2015-07-21. Retrieved
2015-07-18.
11. "How to explain dependency injection to a
5-year-old?" (https://stackoverflow.com/q
uestions/1638919/how-to-explain-depend
ency-injection-to-a-5-year-old) .
stackoverflow.com. Retrieved 2015-07-18.

12. I.T., Titanium. "James Shore: Dependency


Injection Demystified" (http://www.jamess
hore.com/Blog/Dependency-Injection-De
mystified.html) . www.jamesshore.com.
Retrieved 2015-07-18.

13. "To "new" or not to "new"…" (https://web.ar


chive.org/web/20200513185005/http://m
isko.hevery.com/2008/09/30/to-new-or-n
ot-to-new/) . Archived from the original (h
ttp://misko.hevery.com/2008/09/30/to-ne
w-or-not-to-new/) on 2020-05-13.
Retrieved 2015-07-18.
14. "How to write testable code" (http://www.l
oosecouplings.com/2011/01/how-to-writ
e-testable-code-overview.html) .
www.loosecouplings.com. Retrieved
2015-07-18.

15. "Writing Clean, Testable Code" (http://ww


w.ethanresnick.com/blog/testableCode.ht
ml) . www.ethanresnick.com. Retrieved
2015-07-18.

16. Sironi, Giorgio. "When to inject: the


distinction between newables and
injectables - Invisible to the eye" (http://w
ww.giorgiosironi.com/2009/07/when-to-in
ject-distinction-between.html) .
www.giorgiosironi.com. Retrieved
2015-07-18.
17. "the urban canuk, eh: On Dependency
Injection and Violating Encapsulation
Concerns" (http://www.bryancook.net/201
1/08/on-dependency-injection-and-violati
ng.html) . www.bryancook.net. Retrieved
2015-07-18.

18. "The Dependency Injection Design


Pattern" (https://msdn.microsoft.com/en-
us/library/vstudio/hh323705(v=vs.100).a
spx) . msdn.microsoft.com. Retrieved
2015-07-18.

19. "The Java Community Process(SM)


Program - JSRs: Java Specification
Requests - detail JSR# 330" (https://jcp.or
g/en/jsr/detail?id=330) . jcp.org.
Retrieved 2015-07-18.
20. "3.1. Dependency injection — Python 3:
from None to Machine Learning" (https://
web.archive.org/web/20200208005839/h
ttp://python.astrotech.io/design-patterns/
structural/dependency-injection.html) .
Archived from the original (https://python.
astrotech.io/design-patterns/structural/d
ependency-injection.html) on 2020-02-
08.

21. "How Dependency Injection (DI) Works in


Spring Java Application Development -
DZone Java" (https://dzone.com/articles/
how-dependency-injection-di-works-in-spri
ng-java-a) .
22. "Dependency injection and inversion of
control in Python — Dependency Injector
4.36.2 documentation" (http://python-dep
endency-injector.ets-labs.org/introductio
n/di_in_python.html) .

23. "How to Refactor for Dependency


Injection, Part 3: Larger Applications" (htt
ps://visualstudiomagazine.com/articles/2
014/07/01/larger-applications.aspx) .

24. "A quick intro to Dependency Injection:


What it is, and when to use it" (https://ww
w.freecodecamp.org/news/a-quick-intro-t
o-dependency-injection-what-it-is-and-whe
n-to-use-it-7578c84fa88f/) . 18 October
2018.

25. "Dependency Injection


|Professionalqa.com" (https://www.profes
sionalqa.com/dependency-injection) .
26. "What are the downsides to using
Dependency Injection?" (https://stackover
flow.com/questions/2407540/what-are-th
e-downsides-to-using-dependency-injectio
n) . stackoverflow.com. Retrieved
2015-07-18.

27. "Dependency Injection Inversion – Clean


Coder" (https://sites.google.com/site/unc
lebobconsultingllc/blogs-by-robert-marti
n/dependency-injection-inversion) .
sites.google.com. Retrieved 2015-07-18.

28. "Decoupling Your Application From Your


Dependency Injection Framework" (http://
www.infoq.com/news/2010/01/dependen
cy-injection-inversion) . InfoQ. Retrieved
2015-07-18.
29. Martin Fowler (2004-01-23). "Inversion of
Control Containers and the Dependency
Injection pattern – Forms of Dependency
Injection" (http://www.martinfowler.com/a
rticles/injection.html#FormsOfDependenc
yInjection) . Martinfowler.com. Retrieved
2014-03-22.

30. "AccessibleObject (Java Platform SE 7)"


(http://docs.oracle.com/javase/7/docs/a
pi/java/lang/reflect/AccessibleObject.htm
l) . docs.oracle.com. Retrieved
2015-07-18.

31. Riehle, Dirk (2000), Framework Design: A


Role Modeling Approach (http://www.riehl
e.org/computer-science/research/dissert
ation/diss-a4.pdf) (PDF), Swiss Federal
Institute of Technology
32. "Dependency Injection != using a DI
container" (http://www.loosecouplings.co
m/2011/01/dependency-injection-using-di
-container.html) .
www.loosecouplings.com. Retrieved
2015-07-18.

33. "Black Sheep » DIY-DI » Print" (https://we


b.archive.org/web/20150627215638/htt
p://blacksheep.parry.org/archives/diy-di/p
rint) . blacksheep.parry.org. Archived
from the original (https://blacksheep.parr
y.org/archives/diy-di/print/) on 2015-06-
27. Retrieved 2015-07-18.
34. "Spring Tips: A POJO with annotations is
not Plain" (https://web.archive.org/web/2
0150715045353/http://springtips.blogspo
t.com/2007/07/pojo-with-annotations-is-n
ot-plain.html) . Archived from the original
(http://springtips.blogspot.com/2007/07/
pojo-with-annotations-is-not-plain.html)
on 2015-07-15. Retrieved 2015-07-18.

35. "Annotations in POJO – a boon or a


curse? | Techtracer" (http://techtracer.co
m/2007/04/07/annotations-in-pojo-a-boo
n-or-a-curse/) . 2007-04-07. Retrieved
2015-07-18.
36. Pro Spring Dynamic Modules for OSGi
Service Platforms (https://books.google.c
om/books?id=FCVnsq1ZUI0C&q=spring+
pojo+annotation+free&pg=PA64) .
APress. 2009-02-17.
ISBN 9781430216124. Retrieved
2015-07-06.

37. "Go 1.18 Release Notes - The Go


Programming Language" (https://go.dev/
doc/go1.18) . go.dev. Retrieved
2024-04-17.

38. "Awesome Go – dependency injection" (ht


tps://github.com/avelino/awesome-go?ta
b=readme-ov-file#dependency-injection) .
Github. April 17, 2024. Retrieved April 17,
2024.
External links

Wikimedia Commons has media


related to Dependency injection.
Composition Root by Mark Seemann (h
ttp://blog.ploeh.dk/2011/07/28/Comp
ositionRoot/)
A beginners guide to Dependency
Injection (https://www.theserverside.c
om/news/1321158/A-beginners-guide-
to-Dependency-Injection)
Dependency Injection & Testable
Objects: Designing loosely coupled and
testable objects (http://www.ddj.com/
185300375) - Jeremy Weiskotten; Dr.
Dobb's Journal, May 2006.
Design Patterns: Dependency Injection
-- MSDN Magazine, September 2005 (h
ttp://www.griffincaprio.com/blog/201
8/04/design-patterns-dependency-inje
ction.html)
Martin Fowler's original article that
introduced the term Dependency
Injection (http://martinfowler.com/arti
cles/injection.html)
P of EAA: Plugin (http://martinfowler.c
om/eaaCatalog/plugin.html)
The Rich Engineering Heritage Behind
Dependency Injection (http://www.javal
obby.org/articles/di-heritage/)
Archived (https://web.archive.org/we
b/20080313170630/http://www.javalo
bby.org/articles/di-heritage/) 2008-03-
13 at the Wayback Machine - Andrew
McVeigh - A detailed history of
dependency injection.
What is Dependency Injection? (http://t
utorials.jenkov.com/dependency-injecti
on/index.html) - An alternative
explanation - Jakob Jenkov
Writing More Testable Code with
Dependency Injection -- Developer.com,
October 2006 (http://www.developer.c
om/net/net/article.php/3636501)
Archived (https://web.archive.org/we
b/20080311121626/http://www.develo
per.com/net/net/article.php/363650
1) 2008-03-11 at the Wayback
Machine
Managed Extensibility Framework
Overview -- MSDN (http://msdn.micros
oft.com/en-us/library/dd460648.asp
x)
Old fashioned description of the
Dependency Mechanism by Hunt 1998
(https://web.archive.org/web/2012042
5150101/http://www.midmarsh.co.uk/
planetjava/tutorials/language/Watchin
gtheObservables.PDF)
Refactor Your Way to a Dependency
Injection Container (http://blog.thecod
ewhisperer.com/2011/12/07/refactor-
your-way-to-a-dependency-injection-co
ntainer/)
Understanding DI in PHP (http://php-di.
org/doc/understanding-di.html)
You Don't Need a Dependency Injection
Container (https://medium.com/@wro
ng.about/you-dont-need-a-dependency
-injection-container-10a5d4a5f878)

Retrieved from
"https://en.wikipedia.org/w/index.php?
title=Dependency_injection&oldid=1219679853"

This page was last edited on 19 April 2024, at


05:52 (UTC). •
Content is available under CC BY-SA 4.0 unless
otherwise noted.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy