Getting Started with Exrin – Part 1

Please Note: Exrin is no longer actively developed.

This is a guide for developers about to embark on a large or long lifetime project and how to architect to ensure easy and consistent user experience, unit testing and maintainability. It would not be recommended for prototypes, or early iterations of a startup. This will use the framework Exrin, specifically designed for Xamarin Forms.

As Xamarin Forms already includes in-built binding support, a few additional MVVM helpers were added Exrin to remove the requirement any additional MVVM framework. Using Exrin means you do not need any MVVM Framework, only a Dependency Injection framework.

Just as importantly, Exrin has no dependency on Xamarin.Forms or any Xamarin technology.

Exrin is specifically designed for any of these situations:

  1. Enterprise projects or team based projects
  2. Extensive Unit Testing
  3. Focus on Performance, Reliability and Consistency within the app.

The building blocks of this architecture are

  1. MVVM Pattern
  2. Constructor Based Dependency Injection
  3. State + Behaviour based Models
  4. Stateless Services
  5. PCL (Portable Class Libraries)
  6. 1:1 ViewModel to View Mapping

Some of the helper functions included in Exrin are:

  1. Navigation Service
  2. Thread Helper
  3. ICommand / ViewModel Execution
  4. Model Execution

Initialize Exrin

The first steps are adding the Exrin Nuget Package to your native projects and PCL

Then initialize the Exrin framework by placing this code just after the Xamarin.Forms.Init() line.


Setup Structure

Next we want to setup our project for the MVVM pattern. I always like to create a BaseViewModel, BaseModel and BaseView so that we can perform any application wide function in the future if ever appropriate.



Used as the base for all Views (Pages in Xamarin Forms language). Make sure that it implements Exrin.Abstraction.IView.


This can either inherit Exrin.Framework.ViewModel or implement these interfaces INotifyPropertyChanged, IDisposable and Exrin.Abstraction.IViewModel. Choosing to inherit will gain you additional helper functions within the ViewModel.


This must either inherit from Exrin.Framework.Model or implement these interfaces; INotifyPropertyChanged, IDisposable and Exrin.Abstraction.IModel. Inheriting once again provides you with many helper methods.

Enum Keys

While not essential, I like the use of a compiler checked way to reference keys when referencing parts of the system. As such I recommend setting up 2 secs of enums, ViewLocator and Stacks.


Stacks are a concept of Exrin that separate groups of related ViewModels together. For example the authentication view sequence should be completely separated from the actual main view sequence. Neither should interact with each other. In Exrin you would create an AuthenticationStack and MainStack that would both map and contain the navigation of their own views.

When you setup a stack you can either inherit from Exrin.Framework.BaseStack or implement Exrin.Abstraction.IStack.

Wire Up

Because Exrin has no dependency on Xamarin Forms or any Dependency Injection framework, we do need to wire up a few components to ensure Exrin has the ability to perform.


We need to create a class that implements Exrin.Abstraction.IInjection. Please note that it will be required that you inject the instance of IInjection back into itself in the Init() function as other objects will use it. Below is an example using AutoFac.

Navigation Container

Generally in Xamarin Forms you will have a NavigationPage which acts as the container for your root navigation. We need to wire up the calls to the Container with Xamarin Forms local navigation. The class must implement Exrin.Abstraction.INavigationContainer. The example below shows a wire up to Xamarins Forms NavigationPage.


We now move on to the last part of setup which is creating the bootstrapper. In order to ensure Exrin is correctly setup you must inherit from Exrin.Framework.Bootstrapper. This has a few hidden gems such as automatically registering all models and stacks as long as they implement the or inherit the required classes as described above.

Our bootstrapper behind the scenes does a lot all we need to pass through to it is an Action to set the MainPage of Xamarin.Forms and an instance of the Injection class above.

: base(new Injection(), (newView) => { Application.Current.MainPage = newView as Page; }) { }

Loading Exrin Bootstrapper

To finish everything off we just need to call the bootstrapper in the Xamarin.Forms.Application.

And Exrin takes care of the rest.


Next we move on to how to implement commands from the Views to ViewModels and Models in Part 2.