2

I have two questions, really.

I see people add a Services folder to their projects. What is the purpose of that folder?

I see the folders for Services and ViewModels. Now I ran across an article about Repositories. So is it the rule that every time I have classes that have a new use, I should create a folder for them? For instance, if I have a Repository class, then I should make a Repository folder and put them in there instead of the Models folder?

dotnetN00b
  • 5,021
  • 13
  • 62
  • 95

2 Answers2

3

The model folder is only for View Models. Nothing else belongs in it.

I suggest that you move all non UI logic into a separate class library which you reference from the MVC project. Google separation of concerns.

As for the folder naming, it vary from architecture to architecture. Those who use Domain Driven design tend to name the folders

  • Infrastructure
  • Models (domain models and not view models)
  • Repositories
  • Services

while others create root folders for each type of model which they place all related classes in.

jgauffin
  • 99,844
  • 45
  • 235
  • 372
  • you said: "The model folder is only for View Models. Nothing else belongs in it." In ASP.NET MVC? Everything that I've read and seen shows it can be either Domain Models (objects or straight from database) or ViewModels. Matter of fact, a good number of MVC articles/tutorials tell you to make a separate ViewModels folder. – dotnetN00b Apr 17 '12 at 18:58
  • It's because there are no existing guidelines. Anyone can whip up examples, blog entries or a basic MVC project which works just fine. The problem comes when the application grows and you have to start maintaining it. The MVC3 project is a UI layer and should only contain UI logic. At least if you want a well structured solution which uses separation of concerns. – jgauffin Apr 17 '12 at 19:09
1

Folders (generally) have nothing to do with convention over configuration. They are merely a way to organize content. Keep in mind that this will generally create a namespace (of the folder name) for all classes within that folder, also.

In your specific case, then you need to do what makes the most sense. If you are using custom POCOs for your Repositories, then I would agree to create a Repository folder. However, the Models folder is indeed a convention in MVC, where the models that are used by the UI are supposed to be stored there.

Just make sure you store your objects in the most logical place, and you should be good :)

Justin Pihony
  • 66,056
  • 18
  • 147
  • 180