When we design a loosely coupled architecture, which nowadays is a standard practice to separate concerns between our layers, we program against interfaces and not implementations.
The problem we're solving with abstractions is tight coupling, which is when implementation layers are reference one each other directly; for example, the view has a reference of the presentation layer, which in turn has a repository reference that has a service reference class, meaning that the view is coupled to the service layer at the bottom.
To achieve loose coupling, we somehow need to tell the project in runtime that for the interface we are programming against to create this implementation class.
There are three ways to achieve this: using a DI container, Dependency Injection, or with a Service Locator, where you can map an implementation to an interface.
Xamarin.Forms offers an out-of-the-box dependency resolver, DependencyService
, that you can use to register dependencies and...