Ben's Series

Transcript

00:10

00:10

In this video series, we’re going to take a look at the new Xamarin Realm Database solution for saving data locally on your device with your Xamarin.Forms applications. In the past, I’ve used other products or solutions like Sqlite.NET or serializing my JSON to files locally on my device using something like Newtonsoft’s Json.NET library. There’s pros and cons to both, I won’t get too far into those.

00:38

00:38

However, yesterday, Realm announced a new Xamarin database solution and I find it very intriguing in that it uses Link to do a lot of your typical database operations, like create, retrieve, update and destroy. Before we start diving into the actual code on how you can use Realm, I thought I would do a quick tour of an application that I’ve set up.

01:01

01:01

If we run our application, we’ll see it is in a very basic state right now. The idea with this application is that it can act as an address book for us. I’ll have a list of people on the very first screen and I can add new people by tapping Add in the upper right. Anybody that I add should show up on this list. Then, I should be able to click on this list and edit a particular person. In future videos, we’ll explore how we can add multiple addresses to a particular person, like a home address or a work address, etc, to explore the different relationships that can be represented by Realm. That’s the application as it runs. Let’s take a quick look at how I’ve set up this application.

01:47

01:47

I set this up to be a very simple implementation, a MVVM, which for most of you you probably know is Model View ViewModel. I’m not using a particular framework right now. I’m not using FreshMvvm or MvvmCross. My view models are pretty simple. I have a PeopleListViewModel that implements the INotifyPropertyChanged. For the PeopleListViewModel we just have a list of people for now.

02:17

02:17

We will also see that our database service is represented by a class interface and it is getting injected by our ViewModelLocator. Our ViewModelLocator is instantiated and added as a static property to our application class, as you can see here. This ViewModelLocator is reference in our XAML. If I take a look at PersonPage here, you’ll see that I’m specifying the binding context by referencing App.VMLocator and referencing the instance of AddEditPersonVM. Here again, if we go back to the ViewModelLocator, you’ll see when I instantiate AddEditPersonVM, I’m passing an instance of our RealmDBService. Which if we take a quick look at, we’ll see that I haven’t implemented anything yet. We’ll be doing that in the subsequent videos.

03:15

03:15

Lastly, I’m not doing anything fancy with my navigation. If we go to the PeoplePage code behind, we’ll see that I just simply add a ToolbarItem and whenever it gets tapped, I call a method GoPersonPage. I tell the navigation to push the PersonPage instance. As you can see I’m not doing any sort of navigation service, specifically a view model first navigation service, I’m just trying to keep this as simple as possible so other people can build upon it and use their favorite frameworks. In the next video we’ll get started with Realm and creating data records.