简体   繁体   中英

ASP.NET MVC Developing a Layered Architecture

I am new to ASP.NET MVC and as of right now I have the basic understanding of how MVC works. I have created a simple mvc website which uses only one project utilizing the pattern Model-View-Controller.
But I want to learn how to make an mvc web application that uses a specific architecture and having a hard time looking for references online to help me understand it.
I was given a project, to study, and rewrite it but I don't want to be copying each classes one by one without understanding how it's done, I plan to rewrite it from scratch and just use the existing project a guide.

What I need exactly is if someone can point me to where to start reading to understand this project's architecture:

ProjectSolution
 Project.Web
  //An MVC web application

 Project.DataAccess
  //An edmx file (database first)
  Contracts
    IRepository.cs
    IUnitOfWork
  Repositories
    GenericRepository.cs
  UnitOfWork

 Project.Business
  Contracts
    IService1.cs
    IService2.cs
    ....so on
  Services
   Service1.cs
   Service2.cs
   ....so on

From just relying on my personal code reading capability, I can see that from this setup, it consists of 3 different projects, Project.Web is an MVC webapp, while the other 2 are Class Libraries.
Well, technically, I know how this architecture works, but I want to know how to make it from scratch, I mean, which ones are auto generated, which ones are written individually etc etc. And I also want to learn how ViewModel works, because inside Project.Web there is a folder ViewModels that represents a collection of models that is used in the view.

Gahh! I'm lost, I dont know where to start reading. I don't need explanation on each but can you point me where to find a tutorial or something similar to this project for me to know how to build it. Please help! Thank you!



Note: I know this is not a proper question to be posted here but I am desperate and seeking help from the experienced ones to point me somewhere.

From the structure you posted it looks like the solution (One solution) has three different projects:

  • 1- Project.web : That the website project itself where you will have all of your views, css, scripts ... in an "ideal implementation of MVC" (depending who are you talking to) the website project should have no logic at all and it's only responsabilty should be the render of the info to the user. so it's basically the V part of the MVC.
  • 2- Project.DataAccess : that's the M ; the project should manage all the data portion of the project and that includes: DAL, ORM, Repositories, UoW...
  • 3- Project.Business The C part, where all the business logic is taking place , where basically all of your classes doing the hard work , i think of it as the CPU.

You mentioned that the 2 projects are class library projects and the Web is a WebSite project and this is an architecture i follow to organize my projects/solution.

Please note that this is an architecture design to organize your projects and in no way is the only or best one. but with any design you might follow try to respect the SoC (Separation of Concerns) goal of the MVC pattern.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM