IoC is the concept of decoupling an application from the implementation of the service it uses.
Itβs true that IoC goes hand in hand with implementation decoupling interfaces, but I consider this a more general principle. This SO answer gives a very good explanation of the concept.
There are at least two ways to achieve this:
1) DI
2) ServiceLocator
I would not say that the Service Locator pattern is an example of a control inverse. Quite the contrary - when you use the Service Locator, you acquire the necessary dependencies in an active way, no one does it for you (contrary to the DI, where the container handles the dependencies for you, you just need to give it the opportunity to do it - a setter, constructor parameter or implementing an interface method injection).
How is the locator simpler? because it explicitly uses a method call?
I think Martin Fowler refers to the general idea of ββIoC, which can make the code more difficult to understand if you have never seen the IoC / DI concept used earlier. On the other hand, using Service Locator code to get some dependencies may be easier to understand at the first meeting.
What is the best way to use DI with multiple applications?
When you create a component that needs to be reused, the advantage of DI is that it does not make your component dependent on anything other than the original dependency (in the MF example, MovieLister depends only on the MovieFinder interface when using DI). In addition, itβs quite easy for other users to use your component - you just need to pass the dependencies using the DI tools you provided.
When using Service Locator, you also add a dependency on the interface of the service locator itself. With an isolated interface for the locator, this may not be a problem. But it can also be more difficult for users of your component to satisfy the dependencies of your component, as MF writes:
The difference arises if the lister is a component that I provide to the application that other people write. In this case, I know little about the service locator APIs that my clients will use. Each customer can have their own incompatible service locators.