|
|
3
|
|
edited Sep 21 '16 at 9:37
|
This is the most simple explanation about Dependency Injection and Dependency Injection Container I have ever seen:
Without Dependency Injection
- Application needs Foo (e.g. a controller), so:
- Application creates Foo
- Application calls Foo
- Foo needs Bar (e.g. a service), so:
- Foo creates Bar
- Foo calls Bar
- Bar needs Bim (a service, a repository,
…), so:
- Bar creates Bim
- Bar does something
With Dependency Injection
- Application needs Foo, which needs Bar, which needs Bim, so:
- Application creates Bim
- Application creates Bar and gives it Bim
- Application creates Foo and gives it Bar
- Application calls Foo
Using a Dependency Injection Container
- Application needs Foo so:
- Application gets Foo from the Container, so:
- Container creates Bim
- Container creates Bar and gives it Bim
- Container creates Foo and gives it Bar
- Application calls Foo
Dependency Injection and dependency Injection Containers are different things:
- Dependency Injection is a method for writing better code
- Dependency Injection a DI Container is a tool to help injecting dependencies
You don't need a container to do dependency injection. However a container can help you.
This is the most simple explanation about Dependency Injection and Dependency Injection Container I have ever seen:
Without Dependency Injection
- Application needs Foo (e.g. a controller), so:
- Application creates Foo
- Application calls Foo
- Foo needs Bar (e.g. a service), so:
- Foo creates Bar
- Foo calls Bar
- Bar needs Bim (a service, a repository,
…), so:
- Bar creates Bim
- Bar does something
With Dependency Injection
- Application needs Foo, which needs Bar, which needs Bim, so:
- Application creates Bim
- Application creates Bar and gives it Bim
- Application creates Foo and gives it Bar
- Application calls Foo
Using a Dependency Injection Container
- Application needs Foo so:
- Application gets Foo from the Container, so:
- Container creates Bim
- Container creates Bar and gives it Bim
- Container creates Foo and gives it Bar
- Application calls Foo
Dependency Injection and dependency Injection Containers are different things:
- Dependency Injection is a method for writing better code
- Dependency Injection Container is a tool to help injecting dependencies
You don't need a container to do dependency injection. However a container can help you.
This is the most simple explanation about Dependency Injection and Dependency Injection Container I have ever seen:
Without Dependency Injection
- Application needs Foo (e.g. a controller), so:
- Application creates Foo
- Application calls Foo
- Foo needs Bar (e.g. a service), so:
- Foo creates Bar
- Foo calls Bar
- Bar needs Bim (a service, a repository,
…), so:
- Bar creates Bim
- Bar does something
With Dependency Injection
- Application needs Foo, which needs Bar, which needs Bim, so:
- Application creates Bim
- Application creates Bar and gives it Bim
- Application creates Foo and gives it Bar
- Application calls Foo
Using a Dependency Injection Container
- Application needs Foo so:
- Application gets Foo from the Container, so:
- Container creates Bim
- Container creates Bar and gives it Bim
- Container creates Foo and gives it Bar
- Application calls Foo
Dependency Injection and dependency Injection Containers are different things:
- Dependency Injection is a method for writing better code
- a DI Container is a tool to help injecting dependencies
You don't need a container to do dependency injection. However a container can help you.
|
|
|
|
2
|
|
|
This is the most simple explanation about Dependency Injection and Dependency Injection Container I have ever seen:
Without Dependency Injection
- Application needs Foo (e.g. a controller), so:
- Application creates Foo
- Application calls Foo
- Foo needs Bar (e.g. a service), so:
- Foo creates Bar
- Foo calls Bar
- Bar needs Bim (a service, a repository,
…), so:
- Bar creates Bim
- Bar does something
With Dependency Injection
- Application needs Foo, which needs Bar, which needs Bim, so:
- Application creates Bim
- Application creates Bar and gives it Bim
- Application creates Foo and gives it Bar
- Application calls Foo
Using a Dependency Injection Container
- Application needs Foo so:
- Application gets Foo from the Container, so:
- Container creates Bim
- Container creates Bar and gives it Bim
- Container creates Foo and gives it Bar
- Application calls Foo
Dependency Injection and dependency Injection Containers are different things:
- Dependency Injection is a method for writing better code
- a DI Dependency Injection Container is a tool to help injecting dependencies
You don't need a container to do dependency injection. However a container can help you.
This is the most simple explanation about Dependency Injection and Dependency Injection Container I have ever seen:
Without Dependency Injection
- Application needs Foo (e.g. a controller), so:
- Application creates Foo
- Application calls Foo
- Foo needs Bar (e.g. a service), so:
- Foo creates Bar
- Foo calls Bar
- Bar needs Bim (a service, a repository,
…), so:
- Bar creates Bim
- Bar does something
With Dependency Injection
- Application needs Foo, which needs Bar, which needs Bim, so:
- Application creates Bim
- Application creates Bar and gives it Bim
- Application creates Foo and gives it Bar
- Application calls Foo
Using a Dependency Injection Container
- Application needs Foo so:
- Application gets Foo from the Container, so:
- Container creates Bim
- Container creates Bar and gives it Bim
- Container creates Foo and gives it Bar
- Application calls Foo
Dependency Injection and dependency Injection Containers are different things:
- Dependency Injection is a method for writing better code
- a DI Container is a tool to help injecting dependencies
You don't need a container to do dependency injection. However a container can help you.
This is the most simple explanation about Dependency Injection and Dependency Injection Container I have ever seen:
Without Dependency Injection
- Application needs Foo (e.g. a controller), so:
- Application creates Foo
- Application calls Foo
- Foo needs Bar (e.g. a service), so:
- Foo creates Bar
- Foo calls Bar
- Bar needs Bim (a service, a repository,
…), so:
- Bar creates Bim
- Bar does something
With Dependency Injection
- Application needs Foo, which needs Bar, which needs Bim, so:
- Application creates Bim
- Application creates Bar and gives it Bim
- Application creates Foo and gives it Bar
- Application calls Foo
Using a Dependency Injection Container
- Application needs Foo so:
- Application gets Foo from the Container, so:
- Container creates Bim
- Container creates Bar and gives it Bim
- Container creates Foo and gives it Bar
- Application calls Foo
Dependency Injection and dependency Injection Containers are different things:
- Dependency Injection is a method for writing better code
- Dependency Injection Container is a tool to help injecting dependencies
You don't need a container to do dependency injection. However a container can help you.
|
|
|
|
1
|
|
answered May 5 '16 at 11:53
|
This is the most simple explanation about Dependency Injection and Dependency Injection Container I have ever seen:
Without Dependency Injection
- Application needs Foo (e.g. a controller), so:
- Application creates Foo
- Application calls Foo
- Foo needs Bar (e.g. a service), so:
- Foo creates Bar
- Foo calls Bar
- Bar needs Bim (a service, a repository,
…), so:
- Bar creates Bim
- Bar does something
With Dependency Injection
- Application needs Foo, which needs Bar, which needs Bim, so:
- Application creates Bim
- Application creates Bar and gives it Bim
- Application creates Foo and gives it Bar
- Application calls Foo
Using a Dependency Injection Container
- Application needs Foo so:
- Application gets Foo from the Container, so:
- Container creates Bim
- Container creates Bar and gives it Bim
- Container creates Foo and gives it Bar
- Application calls Foo
Dependency Injection and dependency Injection Containers are different things:
- Dependency Injection is a method for writing better code
- a DI Container is a tool to help injecting dependencies
You don't need a container to do dependency injection. However a container can help you.
|
|