Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
lawrence_shaun_introducing_net_maui_build_and_deploy_crosspl.pdf
Скачиваний:
46
Добавлен:
26.06.2023
Размер:
5.15 Mб
Скачать

Chapter 9 Local Data

App Data Directory

The AppDataDirectory property provides the app's top-level directory for storing any files. These files are backed up with the operating system syncing framework.

This property is precisely what you are going to need to use when creating and opening your database files in the next section. So, let’s set up the bits that you will need.

The FileSystem helper class provides a set of static properties, meaning you can simply write

var appDataDirectory = FileSystem.AppDataDirectory;

However, as you have discovered already in this book, it does not lend itself well to unit testing. Instead, you can rely on the IFileSystem interface and register the .NET MAUI implementation with your app builder. Let’s open up your MauiProgram.cs file and add the following line into the CreateMauiApp method:

builder.Services.AddSingleton(FileSystem.Current);

This will register the FileSystem.Current property as the IFileSystem interface so whenever you state that your classes depend on IFileSystem, they will be provided with the FileSystem.Current instance.

Now that you have covered FileSystem and are ready to create your database files, you can learn about database access in .NET MAUI.

Database

A database is a collection of data that is organized. In a database, data is organized or structured into tables consisting of rows and columns. Databases are a much better approach than storing data in files. The ability to index the data makes it easier to query and manipulate. There

261