Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should my models live? Web tier or Data tier? (MVC + NHibernate)

I am setting up an n-tier application with MVC, Ninject, and NHibernate (my first using these technologies). For clarity's sake, the tiers are a "Data" tier, a "Services" tier, and a "Web" tier (all are separate projects).

With MVC, you have your models that are in the "Models" folder. It seems necessary to put my models here to create strongly-typed Views and to generally keep with the philosophy of MVC.

However, with NHibernate, I also need my models in the "Data" tier so that the mapping can take place and that NHibernate can instantiate actual objects to return to the services layer.

Duplicating the classes across projects is not very DRY and abstracting them into their own library doesn't seem to play well with MVC (neither in practice nor philosophy).

Any thoughts? How do you structure your O/RM objects vs MVC models?

like image 428
Jeffrey Harrington Avatar asked Feb 13 '09 17:02

Jeffrey Harrington


1 Answers

I keep Entity Framework models/classes in the data tier and use the Models folder of the MVC project for presentation models and model binders.

like image 114
Craig Stuntz Avatar answered Sep 30 '22 12:09

Craig Stuntz