Default ASP NET MVC

5

I'm learning ASP.NET MVC and would like to learn about design patterns, I have a lot of questions on how to build my Solution.

I would like to know the default names for the Solution, folders, layers, projects, know where to get the dbContext of the Entity Framework, the properties should be inside the folder model or inside another project such as design in 3 beds and etc. The ideal would be if someone had a "skeleton" of Solution so I could see or some example link.

Thanks for the help.

    
asked by anonymous 18.04.2016 / 21:30

1 answer

7

There is no "standard" for the design of the project, other than what Microsoft does for you, which is the most recommended.

On this base model, you already have everything in place. If you create a template with Identity ( Individual User Accounts ) you will see that Context is in the same folder as Models . If Microsoft did so, there is a reason.

When looking at the tutorials on the internet, you will always see numerous types of structures, the most common being to separate into three projects:

  • Models
  • Repository
  • UI

They say that this is a separation in three layers, which is not true. The folder structure does not indicate whether the system has three layers or not: it is just a way of structuring the project, which is not always good.

Below you can see the structure model generated by Visual Studio in the project MVC Music Store , where you you can follow the tutorial and see how Microsoft has organized this project.

On the other hand, it can vary from project to project, creating a project for your Models , for reuse, a project for other platforms ... there are other models, like everything else, but not always there is something that will the best option.

There are some models that you need to know, which are:

  • Every Controller must end with the word Controller, eg: Controller
  • All Attribute should end with the word Attribute, eg CpfAttribute

  • PartialView should begin with _ before the name (not mandatory, but is the default), eg: _Menu .

  • All Context should end with the word Context, (not mandatory, but is the default) eg: MainContext.
  • The Shared folder can be accessed by any View , so place a PartialView that will be accessed by more than one controller in the Shared folder, thus avoiding duplication.
  

In this template you can still add folders to your ViewModels, Helpers, Extensions, etc. Just try not to complicate what there is no need to be complicated.

    
18.04.2016 / 21:59