Understanding Inversion of Control (IoC) Principle

What is IoC???

Implementation Techniques

Let’s take an example

Simple Dependency Diagram of Framework.

Dependency Injection (aka D. I.)

Dependency Diagram after using DI pattern.

Service Locator (aka SL)

Dependency Diagram after using the SL pattern.

Difference between Dependency Injection and Service Locator

The key difference is that with a Service Locator every user of a service has a dependency to the locator. The locator can hide dependencies to other implementations, but you do need to see the locator. So the decision between locator and injector depends on whether that dependency is a problem.

So the primary issue is for people who are writing code that expects to be used in applications outside of the control of the writer. In these cases even a minimal assumption about a Service Locator is a problem.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store