ASP NET MVC standard

Asked

Viewed 186 times

5

I am learning ASP.NET MVC and would like to learn about design patterns, I have a lot of doubt on how to assemble my Solution.

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

Thanks for the help.

  • 1

    The best skeleton is the one that VS itself mounts for you. There is no standard for the name of solutions/projects. Often there are too many complications and no utilities.

  • Thank you for the information.

1 answer

7


There is no "default" for the project structure, except what Microsoft itself mounts for you, which is the most recommended.

In this base template, you already have everything in its proper place. If you create a template with Identity (Individual User Accounts) will see that the 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 is to separate into three projects:

  • Models
  • Repository
  • UI

They say this is a three-layer separation, which is not true. The folder structure does not indicate whether the system has three layers or not: it is just a way to structure 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 can follow the tutorial and see how Microsoft organized this project.

Padrão MS

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, as in everything, but not always that there is something, that will be the best option.

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

  • Every Controller must end with the word Controller, e.g.: ProfileController
  • All Attribute should end with the word Attribute, ex: CpfAttribute

  • Partialview should start with _ before the name (not required, but the default), e.g.: _Menu.

  • Every Context must end with the word Context, (not required, but the default) e.g..
  • Shared folder can be accessed by any View, then put a PartialView that will be accessed by more than one controller in the Shared folder, thus avoiding the repetition of the same.

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.

  • I saw in some examples that a separate project was created for the Models and the MVC (Main Project) Models folder is no longer used, there is a problem in doing this?

  • For example the model layer (Project by Project), Repository (Project by Piece) can have any name? there is no standard for this?

  • 1

    @Mauricioferraz If you are using the Entityframework there is no reason to create a project for Repository. EF is already a Repository, as you can see in this answer. I would say that the way you described it is more of an anti-standard. Separate the models you can, but provided there are reasons. What is the reason for separating if you will not use for other projects?

  • I don’t know, I’d just like to do a project where there’s a pattern where any programmer can understand the project clearly. And let’s also assume that today I create a web project, then a year from now I am asked to create another one with WPF with the same base, i would like to be with a project well thought out and elaborated so in the future not suffer with structural changes that could be avoided if the project had been created in a good pattern.

  • Another thing I’ve also seen is that a good project name starts with Company Name.NomeProject.Layer, I thought there was a place, a document specifying these things.

  • @Mauricioferraz Want a better way for a programmer to understand than what Microsoft itself "teaches"? So, if you’re going to use Models in another project, create a project for it and just reference it. You can create a "Core" project containing this data. But there is no need if you will not use.

  • @Mauricioferraz You can do it this way if you want, but putting the name of the company seems to me an unnecessary redundancy, unless you really need to separate (if you have more than one company, for example).

Show 2 more comments

Browser other questions tagged

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