Chapter 7. Building cross-platform models
This chapter covers
- Creating simple model layers
- Creating and running unit-test projects to test your models
- Structuring more complex model layers with services, repositories, and data models
- Using an ORM to access SQLite
- What REST services and JSON are
- Accessing web services from .NET Standard libraries
In the last chapter we started planning our mobile apps—we looked at the user flows, thought about the UIs, worked out what code would be in each layer, and thought about the threads our code should run on. Then we created a solution and took a look at some of the options and settings available in mobile apps. We talked about two apps: SquareRt (a simple square-root calculator) and Countr (an app for counting things).
Now we’re going to get our hands dirty and write some code. In this chapter we’re going to look at the model layer—looking at ways to build simple and more complex cross-platform model layers, thinking about testing our code, and discussing databases and web services. Everything in this chapter is cross-platform—after all, the big reason for using Xamarin is to share code and write all the business and UI logic once. The examples will be relevant to both SquareRt and Countr, so by following these examples you’ll be able to build up the model layer of both of these apps.