Atitit. How to implement dip, di ,IOC ,Service Locator Different from the contact
1. Dip principle also comes from loose coupling thought direction 1
2. to achieve The dip principle, there are two modes 1
3. The difference between Ioc and di 1
4. Service Locator mode 1
5. Service Locator vs. Dependency injection2
6. Reference 2
1.
Dip Principle also comes from loose coupling thought direction
The benefits of a loosely coupled system are two points:
One thing is that it adapts to the flexibility of change;
Another point is that when the internal structure and implementation of a service change gradually, no other services are affected
2.
to achieve The dip principle, there are two modes
ioc mode control inversion , ioc
Dependency Injection " ( Dependency Injection ). mode
Service Locator mode (Service Locator pattern
IOC , controlling the meaning of inversion , DI is Dependency injection so-called inversion of control , that is, how dependencies are acquired (controll) in turn
Author :: ★ (Attilax) >>> nickname : Span style= "font-family: the song Body;" > old wow Paw   ( attilax akbar al rapanui Attilax   Baroque   Alpha   Rapa Nui   )   Kanji name: Ayron, Email:[email protected]
reprint Please indicate source: http://www.cnblogs.com/attilax/
3.
The difference between Ioc and di
IOC control reversal , focusing on the principle.
DI Dependency Injection: When an object instance is created, an attribute value or other object instance is injected for the object, focusing on implementing
4.
Service Locator mode
The basic idea behind this is that there is an object (the service locator) that knows how to get all the services that an application needs
5.
Service Locator vs. DependencyInjection
First, we face Service Locator and the Dependency Injection the choice between
in fact, both of these models provide basic decoupling capabilities--regardless of which pattern is used, the application code does not depend on the specific implementation of the service interface. The most important difference between the two is: this"Specific Implementation"how it is provided to the application code. UseService Locatormode, the application code sends a message directly to the service locator, which explicitly requires the implementation of the service;Dependency Injectionmode, the application code does not emit an explicit request, and the implementation of the service naturally appears in the application code, which is called"Control Reversal"
control reversal is a common feature of the framework, but it also requires you to pay a price: it will increase the difficulty of understanding, and to the debugging to bring some difficulties. So, as a whole, I will try to avoid using it unless it is necessary. This does not mean that the control reversal is not good, but I think it would be more appropriate to use a more intuitive scenario (e.g. Service Locator mode) in many cases.
One key difference is that: usingService Locatormode, the consumer of the service must rely on the service locator. Locators can hide the user's reliance on a service-specific implementation, but you must first see the locator itself. So the answer to the question is clear: chooseService Locatoror isDependency Injection, depending on"dependency on the locator"whether it will bring you trouble.
6.
Reference
Dependency Injection Control Reversal Service Locator Mode Dependency injection inversion of Control Service Locator Patterns _ Super Classic -yiraner log - NetEase blog . html
Atitit. How to implement Dip, Di, IOC, Service Locator differences from the contact