Best place to host domain objects in an ASP.NET MVC application?

I am just starting my first project in ASP.NET MVC. In my experience with web forms, I usually had a separate project dedicated to my domain layer. Here I will have my objects with a specific domain, along with NHibernate mapping files and some business logic. Most of the examples that I see on the Internet put these classes along with business logic in the Models folder in the MVC application, and then call it from the controller. In my experience, this seems to make it difficult to port this logic to another platform, if necessary. In particular, I was thinking about the possibility of moving it to a webforms application if this is dictated by its environment. This may be a naive question, but is it better to have domain data in your own project or in the Models folder?

+3
source share
3 answers

If you plan to reuse the model outside the MVC application, a separate class library is still an acceptable setting. I do this, but leave the Models folder and put the models in my views.

If you put your DAL in App_Code in a Webforms project, I would put it in Models in your MVC project. Otherwise, continue to use individual projects like you.

+5
source

I plan my decisions in the same way - businessLogic, dataaccess, domain objects are all in the same project. Views (Web, Web services, Windows forms, WPF ..) are all part of their own projects.

Thus, the special user interface code is not filtered into the lower levels of the application. In most web projects, I had to hack into the form of a window in order to insert new data into the database or to manage some type of application that is not “capable in the web environment”.

If I baked at HttpCaching at the business level, I would not be able to switch between views.

+1
source

I use a similar approach. I also use MVC, and I like to have the POCOs domain model in a separate project. For the application that I am creating right now, I have the following projects:

  • Cms.Data li>
  • Cms.Services
  • Cms.Domain
  • Cms.Web

Cms.Data is a data access project that translates from LinqToSql or Entity Framework model of POCOs to Cms.Domain and vice versa. Cms.Services is a business logic service project that brings / sends POCO from / to the data layer. Finally, Cms.Web is an MVC project that uses services from controllers and POCOs as a model.

I like critics :)

+1
source

All Articles