Search code examples
c#xamarinxamarin.formsxamarin.essentials

What is the difference between Xamarins.Essentials and Xamarin.Forms DependencyService


I'm a new developer on Xamarin and I was guessing what is the difference between Xamarins.Essentials and Xamarin.Forms DependencyService?

I understood that Xamarins.Essentials is a framework providing cross-platform API in order to use geolocation, connectivity etc... Whereas DependencyService is functionality in Xamarin.forms in order to use the Android or iOS platforms functionalities.

Is my understanding right? Are there other differences?

Thank you for your help, Clement


Solution

  • You are totally correct.

    DependencyService is being used in order to "unveil" native functionality to your shared project. Basically, you write "native" code in the OS-specific projects, which through Dependency injection can be used in your shared project. You can read more for DependencyService in the official docs - Introduction & Registration & Resolution

    Xamarin.Essentials is your must-have toolkit. It supports anything from Geolocation, through Battery & Preferences. The good thing with Essentials is that it strips any code that it is not using. So, even though it has many functionalities, during building & archiving, it only leaves what is referenced through your code. Essentials is also open-source - repo.

    Basically, when it comes to a choice - if it is built-in into Essentials - use Essentials. If it is not, write your own code and expose it through DependencyService.