开发者

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

开发者 https://www.devze.com 2023-04-11 05:44 出处:网络
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.

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?


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.


  1. You can create a library that contains the viewmodels and is used by both client projects if it is a Portable Class Library. (They were created for just this scenario.)

I know FluentValidation has support for WP7 but I'm not sure of the differences in that version or if you'll need to do anything special to work with a PCL.

0

精彩评论

暂无评论...
验证码 换一张
取 消