Creating and using platform-specific services within your app
As mentioned in the introduction to this chapter, we created a customized NavigationService
Interface and Class and then updated our BaseViewModel
to include a property reference to our INavigationService
so that each of our ViewModels can reference it.
The benefits of using an interface and class to define a platform-specific service is that they can be used within each of your ViewModels. Then, the implementations of the service can be provided using dependency injection.
This is achieved by declaring the DependencyService
meta tag, with each of those implementations being actual services, or even Mock services that can be used to unit test your ViewModels, which we will be covering in Chapter 13, Unit Testing your Xamarin.Forms Apps.
In addition to the NavigationService
interface and class that we created within our previous chapter, we can use a couple of other platform-specific feature services to enrich the data and user experience...