terminology - Difference between ioc and dependency injection -


The difference between IOC and dependency injection Explain dependency injection in the spring ISC means the control is inverted. Public class MyComponent {Public MyComponent () {:} Public Zero DoSomeWork:

See some "strong coupled code" ("MyComponent" depends on "logger"): ( ) {Var logger = new logger (); :}}

We can change it to use "interface", but someone has to provide "implementation":

  public class MyComponent {Public MyComponent () {:} Public Zero DoSomeWork () {ILogger logger = ...; // Who is this to provide? :}}  

Dependence injection (DI) is a specific implementation of IoC

  // dependency injection pattern public class MyComponent {Private ILogger _logger; Public MyComponent (Illogger logger) {_logger = logger; } Public Zero DoSomeWork () {// Logger component use _logger.Log (); :}}  

Another implementation service locator is.

  // Service Locator Pattern Public Class MyComponent {Public MyComponent () {:} Public Zero DoSomeWork () {IiEGG Logger = ServiceLocator.net Service (); :}}  

Martin Fowler states: "With the service locator, the application class has explicitly inquired it through a message. There is no clear request with injection, service Service is visible in the class - therefore control is inversion. "

Apart from this:" The choice between service locator and dependency injection is less important than the principle of separating the services within an application. By use You can check this post:

In addition to:

By Dino Esposito

By Martin Faller < / P>

by Martin Fowler

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -