I'm just starting my first project in ASP.NET MVC. In my webforms experience, I would usually have a separate project dedicated to my domain layer. In here, I would have my Domain specific objects along with my NHibernate mapping files and some business logic. Most of the examples I am seeing online are putting these classes along with business logic into the Models folder on the MVC app, then calling into this from the controller. From my experience, this would seem to make it harder to move that logic into a different platform if need be. Specifically, I was thinking about the possibility of needing to move it to a webforms app if the environment dictated it. This might be a naive question, but is it better to have the Domain data in its own project, or in the Models folder?
If you plan to reuse the model outside of the MVC app, a separate class library is still an acceptable setup. I do that, but leave the Models folder and put the models for my views in it.
If you would put your DAL in App_Code in a Webforms project, then I would put it in Models in your MVC project. Otherwise, keep using separate projects like you have been.
I layout my solutions in a similar manner -- businessLogic, dataaccess, domain objects all reside in one project. The view(s) (Web, Web services, windows forms, WPF..) all go into their own separate projects.
That way UI specific code doesn't filter down in to the lower layers of the application. In most web projects I've had to hack together a windows form to inject new data into the database or manage some type of the application that isnt' fesiable in the web medium.
If I bake in HttpCaching at the business level I wouldn't be able to switch between views.
I use a similar approach. I'm using MVC too and I like having a POCOs domain model in a separate project. For the app I'm building right now I have the following projects:
- Cms.Data
- Cms.Services
- Cms.Domain
- Cms.Web
The Cms.Data is a data access project that makes the translation from LinqToSql or Entity Framework model to the POCOs model in Cms.Domain and viceversa. The Cms.Services is a services project with the business logic wich brings/sends the POCOs from/to the data layer. Finally the Cms.Web is the MVC project wich uses the services from the controllers and the POCOs as Model.
I like receiving critics :)