Xamarin Native Project Architecture

Introduction

The Xamarin native term refers to the platform specific applications. By using Xamarin, we are able to create native applications in Android, iOS, or Windows. In native Xamarin applications, we are creating platform specific applications such as Xamarin.Android, Xamarin.iOS and Xamarin.Windows. Each native platform consists of UI / Views, which can be designed and developed in native environments; in Android, we are creating UI in .axml format, where for iOS, we are using storyboards. Thus, in this article, we will learn how to create Xamarin native project architecture.

Solution

Description of the architecture is given below.

To create Xamarin native solutions, you need to follow the steps given below.

Step 1

Open Visual Studio and create New Project. Select Cross Platform and select Blank app (native portable).

Native Portable

Native Portable

In the screenshot given above, you can see the solution architecture, which consists of four projects called
Portable, Droid (Android Project), iOS (iOS Project), and WinPhone(Windows Project). Here, the portable project consists of the code, which is accessible across all the platforms and the platform specific code like UI, Activity, native functionality (Bluetooth, Wi-Fi etc.).

  • In portable projects, we are using the business logic of the app, it consists of all the Models, ViewModels, Helpers etc.
  • In Droid projects, we are creating Views in .axml and binding them with the ViewModel, which is inside the portable project.
  • In iOS projects we are creating views in storyboard and binding them with the ViewModel, which is inside the portable project.
  • The portable project will be used across all the platforms and to achieve this, we are using MVVM pattern. Here, we are separating the business logic with the UI.

Step 2

In this project, we are going to use MVVM library, so go to portable project and select to Add NuGet Packages. Add MvvmLightLibs.

Here, we are using MVVM (Model-View-View-Model) pattern to develop the application.

Native Portable

Step 3

Now, add the folders given below in your portable project as ViewModel, Model, Repositories, Helpers and Services.

Native Portable

Folder Details are as follows

  • ViewModels
    Consists of all the ViewModels.

  • Models
    Consist of all Models.

  • Helpers
    Consist of Helpers such as Network Connectivity etc.

  • Services
    This layer will decide whether the code requires data from SQLite or need an API call.

  • Repositories
    Here, we are putting in all API calls.

Now, the solution is ready to be used.

Next Recommended Readings