Asp.net MVC class structure

Asked

Viewed 630 times

2

Hello, I’ve been studying for a while asp.net mvc, and developing small projects, evolving and gaining knowledge every day more.

One question I have, and I didn’t find much subject on the internet, was about the best practice for structure and organization of folders and classes in an mvc project, whose classes are not Model, and Controller. For example, a class of Constants, or utilities

1 answer

4


You can organize however you like, 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 they prefer and as each situation requires. Try to answer the question: why organize by folders and not leave everything thrown at the root?

The answer to 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. Models and Controllers folders exist because they’re useful: your view models are in the models folder and your controllers are in the controllers folder - you know exactly where to look.

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

Regarding the separation of projects, I believe you have to think about a logical division of your application and think about the things you don’t want to mix. A simple example is to separate a project Aplicacao.Dominio to encode your domain model. The motivation for this is: you don’t want to mix your domain code with your MVC user interface code and at the same time you don’t want the domain types to depend on your interface.

This separation, if done correctly, allows you to evolve the domain without tampering with the interface design and then proves useful.

  • Good face, so the issue of organizing folders, in webforms projects, for example I created an Appclass folder, and inside it, I put my classes and if necessary subfolders, to make it better organized. But as I’m starting in MVC, I didn’t know if this would be the best option or not. Now with your answer I already have a north. And @Leonardo, I was interested in the question of project Application.Domain, do you have any reference to indicate me? I want to know a little more about this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.