leora
leora

Reputation: 196689

In asp.net-mvc, Is there any good reason to keep your model in the same project?

I have an asp.net-mvc site and recently I have wanted to generate emails with the same data that i am using to render to a webpage. So slowly but surely I started moving a lot of my model and data access code into a seperate project so i can do the email generation stuff from a command line app or a service, etc (no dependency on any web stuff) . . if I take this one step further, I am now thinking I should just move all of my model and data access code outside of the MVC project so its a bit more future proof. I know MVC gives you the default Model folder inside the web project. Is there any reason to keep it there?

I basically want to protect myself from accidentally having a dependency on System.Web.MVC inside my model or data access code.

Upvotes: 0

Views: 109

Answers (2)

Pieter Germishuys
Pieter Germishuys

Reputation: 4886

If it makes sense to start extracting your models into a separate project, then you should do it. I generally find that I start out with MyProject.Core and MyProject.Web as you want to share your models with non-front end type of work some of the time.

The MyProject.Core will contain the models and my persistence layer and my Web project will contain the FrontEnd objects with it's viewmodels which I tie to my models using Automapper.

Upvotes: 1

Judo
Judo

Reputation: 5247

It makes development a little quicker as only one project has to be built, but I find it preferrable to keep the model and data access code in a separate project in the same solution. The biggest advantage is that it makes in very easy to use the model other projects such as an API or another website.

Upvotes: 2

Related Questions