Class structure in Asp.net MVC

2

Hello, at one time I've been studying asp.net mvc , and developing small projects, evolving and getting more and more knowledge.

A question I have, and I did not find much about it on the internet, was about the best practice for structure and organization of folders and classes in a mvc project, whose classes are not of Model , and Controller . For example, a class of Constants, or Utilities

    
asked by anonymous 09.03.2015 / 00:11

1 answer

4

You can organize as you wish, just be consistent in your choice of organization in your project. In reality, there is no right way to organize the folders and files of a project, each one does as he prefers and as each situation requires. Try to answer the question: why organize by folders and not leave everything played in the root?

The answer of this, logically, is for you not to get lost, to know where everything is quickly so that your development is productive. This is what you have to keep in mind when creating a folder structure. The Models and Controllers folders exist because they are useful: their view models are in the models folder and their controllers in the controllers folder - you know exactly where to look.

In your example, you can create a folder Utilities for example and put your utilities classes inside. You can create a Configuration folder and place your classes related to application settings. The important thing is to understand that each case is a case.

With regard to project separation, I believe you have to think of a logical division of your application and think of the things you do not want to mix. A simple example is you separate a Aplicacao.Dominio project to encode your domain template. The motivation for this is: you do not want to mix your domain code with your MVC user interface code and at the same time you do not want domain types to depend on your interface.

This separation, if done correctly, allows you to evolve the domain without touching the interface design and it proves useful.

    
09.03.2015 / 01:53