The Xamarin.Forms DependencyService versus third-party alternatives

In addition to providing the core building blocks for the MVVM pattern, Xamarin.Forms also includes a very basic service to handle dependency registration and resolution, the DependencyService. We actually used this service in the preceding chapter to register and resolve our custom navigation service. Like many of the services and components built into the Xamarin.Forms toolkit, the DependencyService is designed to help get users up and running quickly by providing an easy-to-use basic implementation. It is in no way the only way of handling dependencies in a Xamarin.Forms mobile app and, in most complex apps, you will quickly outgrow the capabilities of the Xamarin.Forms DependencyService. For example, the Xamarin.Forms DependencyService doesn't provide a way of doing constructor injection. There are several third-party alternatives to the DependencyService that allow much greater flexibility, such as Autofac, TinyIoC, Ninject, and Unity, among others. Each of these libraries are open sourced and, in most cases, community maintained. They all implement the patterns in slightly different ways and offer different key benefits depending on the architecture of your app.

In the next couple of sections, we will build two new platform-specific services and use the Ninject library to register and use them in our TripLog app. We will also update the navigation service from Chapter 3, Navigation Service, to be registered in Ninject, instead of the Xamarin.Forms DependencyService.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.19.185