asp.net-mvc-3windows-phone-7fluentvalidationfluentvalidation-2.0

How do I validate ViewModels across an ASP.NET MVC and a Windows Phone Project?


I want to create an application that has both an ASP.NET MVC 3 web client and a Windows Phone 7 phone client. The application data is stored in SQL Server and needs to be accessed from both clients.

Given that scenario, I have two questions:

  1. I want to reuse the view models I use in the (existing) MVC application in my phone app and validate these using FluentValidation. Am I supposed to create a new class library called ViewModels and reference it in both client projects, or is there a better way?
  2. Would it be appropriate to create a Web Service that both clients talk to? Or is it better to access the data via the MVC web project?

How would an appropriate solution structure for that scenario look like?


Solution

  • Am I supposed to create a new class library called ViewModels and reference it in both client projects, or is there a better way?

    Yes. Except you can't. Or well, you can, but you need two different project types for this. I'll recommend using shortcuts in one of the projects.

    a "Windows Phone Class Library" isn't accessable from ASP.NET, and visa-versa.

    Would it be appropriate to create a Web Service that both clients talk to?

    Yes, very appropriate

    Or is it better to access the data via the MVC web project?

    You could host the web-service in your web-project. But a seperate service is easier to maintain, if you have the ability to host it.

    With RestSharp you could easily integrate it with ASP.NET MVC.