Book Image

Cross-platform UI Development with Xamarin.Forms

By : Paul Johnson
Book Image

Cross-platform UI Development with Xamarin.Forms

By: Paul Johnson

Overview of this book

Table of Contents (22 chapters)
Cross-platform UI Development with Xamarin.Forms
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
In the Beginning…
Index

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...