I am relatively new to MVC and trying to put together a framework for a MVC 4 based web application.
This question is somewhat similar is nature to mine, but I have a particular situation that I want the community to evaluate and provide me inputs on.
I have a software system that has two components - an MVC 4 web application and a windows service. The "model" layer (I am referring to the domain tables etc.) will be accessed by both the Windows Service and the Web Application.
I also have plans to expose a good amount of functionality to mobile apps in the near future and the API will also consume the model.
The overlap in functionality will be in case of the web application and the API (mobile apps)
Here are some questions specific to my case:
- Is it a good idea to reuse View Models across the Web application and the API for the same functionality (e.g. update address of an individual exposed on the web and the mobile app)? Where should the validation (e.g. address validation - like address line, city, state, zip all combined) reside?
- The Windows Service functionality is more complimentary in nature to the web+API (e.g. a nightly job that sends out reminder emails), but will likely overlap with the "Model" part used by the Web+API. Is it a good idea that the service use the "Model" directly or have a layer like the "ViewModel". Where would validation go in this case?
- Another conceptual question that I would like more information on is - The attribute driven validation is implemented by virtue of the MVC framework, i.e. it is the MVC architecture that takes the view model, finds the validation attribute on the view model properties and injects relevant validation. How would this attribute driven validation work in case of an API and when the model is consumed by a windows service?