Help Understanding the ASP.NET MVC 4 Options and Selecting Projects RRS feed

  • Question

  • As I’m trying to piece together a new solution for our product and with all the different technologies, frameworks, solutions, etc. out there, I’m getting confused on which technologies to recommend and how they all fit together.

    What we want is one set of server-side code, business logic, domain, database, etc. that is accessible from 3 separate presentation/client platforms: native mobile apps, mobile browsers, and desktop browsers.  By saying “native mobile apps”, we mean, for example, an iPad app that you would download from the app store.  By saying “mobile browsers” and “desktop browsers”, we mean that we need a presentation layer that serves up views optimized for mobile browsers if the user navigates to the site on a mobile device, while, at the same time, serves up ‘regular’ views that are optimized for desktop/laptop browsers if the user is using their desktop/laptop computer.

    For the server-side, we are planning on: an application layer (class library project, C# classes, interfaces, etc.) which will work as a façade for the domain model layer, a domain model layer (class library project, C# classes, interfaces, etc.) which will contain POCO domain entities and domain services, and a data access layer (Microsoft ADO.NET Entity Framework (Code First), DbContext, POCO, Repository & Unit of Work patterns).


    1.  Do we need a RESTful WCF Service Layer for native mobile apps to be able to access the server-side stuff?

    2.  Could we use ASP.NET Web API instead of a RESTful WCF Service Layer for native mobile apps to be able to access the server-side stuff?

    3.  Can the ASP.NET Web API project be used to allow native mobile apps access into the server-side stuff?

    4.  Is the ASP.NET Web API project mainly for writing HTML pages using JavaScript (and various JavaScript frameworks, like jQuery and Knockout) instead of the Razor view engine type of views?

    5.  We’re wanting to use ASP.NET MVC 4 with the Razor view engine for the mobile and desktop browser options, so is it better to start with the ASP.NET MVC 4 Mobile project template (and can it handle ‘regular’ views?)?  Or, start with the ‘normal’ ASP.NET MVC 4 project template and manually add in the mobile pieces (like jQuery Mobile)?

    6.  In our Visual Studio solution, do we need to have both an ASP.NET MVC 4 project (for the desktop and mobile browsers options) AND an ASP.NET Web API project (for the native mobile app options)?

    7.  If we do have to have two separate projects (an ASP.NET MVC 4 project and an ASP.NET Web API project) in our solution, do we build them to the same location and make them use the same URL?

    I hope all this makes sense.  I’ll try to provide clarification if things are unclear.

    Thanks for the help!

    Wednesday, June 20, 2012 3:29 PM

All replies

  • Hi

    I'd break down your problem into several projects within one solution - as far as I understand your requirements it would go something like:

    Main Solution 

     - Data Access project (Holds all code related to the Database and CRUD)

     - Web API project (Business layer referencing Data Access project providing info to Requests)

     - MVC 4 Internet project (Controllers and Views for "Desktop" referencing Web API)

     - MVC 4 Mobile (Web) project (Controllers and Views for "Mobile" referencing Web API)

     - VSNOMAD (Native Mobile) project (Views & View Models for native phone application referencing Web API)

    To manage the hosting there are several ways you could do the following

    Host the "Desktop" version on www.someurl.com (issue a 301 from someurl.com to www.someurl.com)

    Host the "Mobile web" version on m.someurl.com 

    Host the Web APi on "api.someurl.com" (with security)

    The Desktop/Mobile/Native versions can then make requests to api.someurl.com internally. To "switch" from Desktop to Mobile simply detect device type on Session_Start in global.asax and redirect as appropriate. 

    A similar scheme based on Virtual directories could also be used.

    • Edited by L. Baughan Monday, June 25, 2012 12:44 PM
    Monday, June 25, 2012 10:59 AM
  • Thanks for the reply.  Your suggestions are interesting.  I hadn't thought to use a Web API project as the business layer (I guess because all the examples I've seen use a Web API project with views, HTML, JavaScript, etc. to present the user interface too, as opposed to a business layer that has to user interface).  I'm not even sure how to make that work - but I'll try to look into that further.

    Thanks again.

    Tuesday, June 26, 2012 2:27 PM
  • No worries glad I could help - I know netflix amongst others use OData for a data/business layer that may also be worth considering (Support for OData is a first class citizen in dot net) so it might be a more appropriate fit than Web API depending on the requirements!

    VSNOMAD is a Visual Studio Extension created by Red Gate built on top of PhoneGap to offer cross mobile device application creation within the IDE - currently in Beta but knowing RedGate and their products it's definitely the route I'd take.

    Additionally it might be worth merging the Data Access & Web API projects (again depending on flexibility and requirements) I believe there are some tutorials for doing this on the asp.net site.


    Tuesday, June 26, 2012 2:41 PM