![Hands-On Mobile Development with .NET Core](https://wfqqreader-1252317822.image.myqcloud.com/cover/565/36698565/b_36698565.jpg)
Inversion of Control
IoC is a design principle in which the responsibility of selecting concrete implementations for dependencies of a class is delegated to an external component or source. This way, the classes are decoupled from their dependencies so that they can be replaced/updated without much hassle.
The most common implementation of this principle is using the service locator pattern, where a container is created to store the concrete implementations, often registered via an appropriate abstraction, as shown in the following diagram:
![](https://epubservercos.yuewen.com/33AE73/19470378308806506/epubprivate/OEBPS/Images/a6721c5e-f161-4315-9925-93d107234dfa.png?sign=1739250071-pwAfiVkDI0H2GfzWJVkZ40hCRAx4NG59-0-54c69448fca305cbff0d6a87809b5943)
Xamarin.Forms offers DependencyService, which can be especially helpful when you're creating platform-specific implementations for platform-agnostic requirements. We must also remember that it should only be used in Xamarin.Forms platform projects; otherwise, we would be creating an unnecessary dependency on Xamarin.Forms libraries.