Xamarin MVC Project Separation & Fluent Validation – Part I

Recently at my job, we’ve decided to make a new project base for our company. We currently have an MVC 3 base, but considering MVC 5 is the new norm, it is time we get caught up with the latest and “greatest” (greatest used loosely). We decided that we were going to change our strategy with communicating with the database. Currently we use an ORM provided by Microsoft called Entity Framework. Entity Framework is a great ORM, however, when dealing with multi-million(s) set of records we’ve found it to be sub-par. I leave that for another topic at a later date.

The goal of this semi tutorial is to outline a project setup that has a model, service, and data layer, with the model and service layer being reusable from a MVC site to an Android and iOS app. However, with this project setup you could easily implement a WPF application, Silverlight, or even console apps. Resulting in a true “N-tier” architecture.

Below are some of the technologies that are going to be talked about and I’m going to assume some knowledge on them:
1.) AutoFac
2.) FluentValidation
3.) SqLite.NET
4.) Xamarin
5.) NHibernate

Project Setup

First thing we need to do is create a new solution and add two Solution Folders.  Create one for “Web” and one for “Mobile”, we separate these just for our convenience.  Then we need to start adding projects to the new solution.  Using Visual Studio 2015 you should have everything you need built in to your templates if not you may need to download Xamarin from here and of course make sure you have NuGet installed in Visual Studio.  Next you’re going to add four Portable Class Libraries and suffix them with “*.Configuration”, “*.Models”, “*.Services”, “*.Validation”. It is imperative that these be a “Portable Class Library” in order to get this to work correctly.  Below are the options you will want to set for all four PCLs.

PCL Settings

Continue reading “Xamarin MVC Project Separation & Fluent Validation – Part I”