2

I have a question about the 'Models' folder or layer in a ASP.NET MVC or Web API application (I'm using Web API, but should apply to both based on what I'm asking). See in all the basic examples on trying to use MVC or Web API as the entire architecture, the 'Models' folder is typically populated with classes like Customer, Orders, Address, etc.

However, all of my entities have been extracted out to their own domain/business layer and therefore I have no model classes in the UI layer.

Now I still need ViewModels to be the final shaped data for my MVC apps, but regardless for MVC where I need views or Web API where the injected repository returns the shaped data without a view, I still have no need for the 'Models' folder in my UI layer when porting out those entities to another separate layer.

Is this OK? In the case of using MVC where I still may not have any Model classes in the UI layer, does the 'Models' folder need to rather contain my ViewModels as discussed here? Fat model / thin controller vs. Service layer I think leaving the 'Models' folder empty and creating a separate 'ViewModels' folder makes more sense to show the Models exist, but are in another layer.

Help is appreciated on each question within, thanks!

Community
  • 1
  • 1
atconway
  • 20,624
  • 30
  • 159
  • 229

2 Answers2

4

You're doing it right. In a non-trivial MVC application, your Models folder would typically contain only ViewModels. If your ViewModels are in another layer, that's also fine.

While ASP.NET MVC is an opinionated framework, and certain conventions must be followed, the location of your models is not one of them. Moving your views, however, is another story.

jrummell
  • 42,637
  • 17
  • 112
  • 171
  • 1
    I agree, in most non-trivial cases MVC becomes more of VMVC :) – Sebastian K Jan 09 '13 at 19:41
  • My Views (MVC) and Controllers stay put. Just wondering about no true Model entity type classes in UI, and the practice of filling the 'Models' folder with ViewModels instead. You helped clear this up. – atconway Jan 09 '13 at 20:19
2

I don't think it makes any difference whatsoever. If you want to save a newbie developer 2 minutes, you could put a README.TXT inside the empty models folder.

jlew
  • 10,491
  • 1
  • 35
  • 58