ASP.NET MVC 开发分层架构 [英] ASP.NET MVC Developing a Layered Architecture

查看:12
本文介绍了ASP.NET MVC 开发分层架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 ASP.NET MVC 的新手,现在我对 MVC 的工作原理有了基本的了解.我创建了一个简单的 mvc 网站,该网站仅使用一个使用模型-视图-控制器模式的项目.
但是我想学习如何制作一个使用特定架构的 mvc web 应用程序,并且很难在网上寻找参考资料来帮助我理解它.
我得到了一个项目,要学习并重写它,但我不想在不了解它是如何完成的情况下一个一个地复制每个类,我打算从头开始重写它,并仅使用现有项目作为指南.

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

仅凭我个人的代码阅读能力,从这个设置可以看出,它由3个不同的项目组成,Project.Web是一个MVC webapp,另外2个是Class Libraries.
嗯,从技术上讲,我知道这个架构是如何工作的,但我想知道如何从头开始,我的意思是,哪些是自动生成的,哪些是单独编写的等等.我还想了解 ViewModel 的工作原理,因为在 Project.Web 中有一个文件夹 ViewModels 代表视图中使用的模型集合.

呸!我迷路了,我不知道从哪里开始阅读.我不需要对每一个进行解释,但你能指出我在哪里可以找到教程或类似于这个项目的东西,让我知道如何构建它.请帮忙!谢谢!

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:网站项目本身将您的所有视图、CSS、脚本...置于理想的实现MVC"(取决于您在与谁交谈)网站项目根本不应该有逻辑,唯一的责任应该是将信息呈现给用户.所以它基本上是 V 部分MVC.
  • 2- Project.DataAccess:这就是 M ;该项目应该管理项目的所有数据部分,包括:DAL、ORM、存储库、UoW...
  • 3- Project.Business C 部分,其中所有业务逻辑正在发生,基本上你所有的课程都在努力工作,我认为它是 CPU.
  • 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.

您提到这两个项目是类库项目,Web 是网站项目,这是我用来组织项目/解决方案的架构.

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.

请注意,这是一种用于组织项目的架构设计,绝不是唯一或最好的.但是对于您可能遵循的任何设计,请尝试尊重 MVC 模式的 SoC(关注点分离)目标.

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.

这篇关于ASP.NET MVC 开发分层架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆