Reader small image

You're reading from  Cross-platform UI Development with Xamarin.Forms

Product typeBook
Published inAug 2015
Reading LevelBeginner
Publisher
ISBN-139781784391195
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Paul Johnson
Paul Johnson
author image
Paul Johnson

Paul Johnson has been writing software since the early 1980s on machines ranging from the ZX81 and servers to his trusty Mac, and has used more languages than he can remember. He is a qualified scuba diver and college lecturer. Paul lives with his wife, kids, and pets, and listens to an inordinate amount of rock and metal on Primordial Radio. This is his third book for Packt.
Read more about Paul Johnson

Right arrow

Dependency injection


Another important aspect of Xamarin Forms is based on something called Inversion of Control (IoC).

Inversion of Control?

Once the app has started, the PCL runs the show; it is in control. However, certain things have to use the device or facilities on the device, and so control is passed to the application (control has been inverted). This can be considered using the following diagram:

https://jonlennartaasenden.files.wordpress.com/2015/01/traditional-vs-di.gif

IoC and Dependency Injection go hand-in-hand. DI (as the name implies) injects information directly into the PCL. There is a rule, though, to do this: the class being called must have a default constructor for the class (normally, the default constructor for any class is not required).

Implementing DI

Let's take the following example for DI. A PCL only contains a subset of the standard libraries; one important omission is anything to do with the filer. When you create a SQLite database though, a file has to be written...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Cross-platform UI Development with Xamarin.Forms
Published in: Aug 2015Publisher: ISBN-13: 9781784391195

Author (1)

author image
Paul Johnson

Paul Johnson has been writing software since the early 1980s on machines ranging from the ZX81 and servers to his trusty Mac, and has used more languages than he can remember. He is a qualified scuba diver and college lecturer. Paul lives with his wife, kids, and pets, and listens to an inordinate amount of rock and metal on Primordial Radio. This is his third book for Packt.
Read more about Paul Johnson