DependencyService
is used to call the native platform specific implementation of some feature from the PCL or Shared project. Thus, it helps us in doing anything that native app can do.
Steps:
- Interface: Define an interface for specific feature into the PCL or shared Project.
- Implement it per Platform: Add class into the Platform specific project and implement this interface into that class by inheriting this interface to it.
- Registration: Register each of these platform specific classes with
DependencyService
by providing metadata attributes to it.
Now, we can access the native implementation of this class into PCL or Shared project by DependencyService
.