Xamarin.Forms Essentials by Gerald Versluis

Xamarin.Forms Essentials by Gerald Versluis

Author:Gerald Versluis
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


Automatic wiring of BindingContext

Automatic wiring of Page events (e.g., appearing)

Basic methods (with values) on PageModel (init, reverseinit)

Built-in IOC container

PageModel Constructor Injection

Basic methods available in Model, like Alert

Built-in Navigation types for SimpleNavigation, Tabbed, and MasterDetail

I don’t cover all of them in detail here, as you will see how it works in the next chapter. The one thing that I do want to point out here is that FreshMvvm uses convention over configuration. This means that you do not need any code to map the pages to the PageModels. As long as you keep the naming consistent, FreshMvvm will automatically understand which page belongs to which PageModel. This is the same convention I have been using throughout this chapter: the page will be named as IdentifierPage, where identifier has to be a self-describing name for the page. The PageModel should then be named IdentifierPageModel, where identifier is the same as the one used for the page.

FreshMvvm also includes an IOC container, which stands for Inversion of Control. This is another pattern that can be used to decouple your code. Basically, it means that you define an interface for classes that other classes have a dependency on. We have seen this kind of behavior in the DependencyService. By wrapping the dependency classes in interfaces, you can register any implementation of that interface if you might need different behavior.

Then, you inject that interface through the constructor of the dependent class. That way, the dependent class does not have to have a hard reference to the class that implements the logic you need. By solving it with the IOC pattern (also known as Dependency Injection—DI), you can easily swap out one implementation with the other, without having to touch any other code. A quick example of how this works is shown in Listing 5-7.

// Register an interface with its implementing class

FreshIOC.Container.Register<IDatabaseService, DatabaseService>();



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.