ASP .NET MVC架构如何融入传统的多层架构 [英] How ASP .NET MVC architecture fits into the traditional multi layered architecture

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

问题描述

从业务层,服务层,数据访问层和presentation层到MVC设计模式架构的Web应用程序的传统方式移动,我很难理解它的旧模式如何适应。

Moving from the traditional way of architecting web applications with a Business Layer, Service Layer, Data Access Layer and a Presentation Layer to the MVC design pattern, I find it difficult to understand how it fits in the old model.

有似乎是MVC模型本身已经具有配发的所需要和使用的关注的分离完成经由分层架构来实现。有人可以阐明这个问题的一些光吗?

It seems to be that the MVC model itself already has done allot of the separation of concerns that is needed and used to be achieved via a layered architecture. Can someone shed some light on this subject please?

作为参考,下面是我的理解,请在此分享你的看法

MVC的视图和控制器与-are-的视图模型沿presentation层

MVC Views and Controllers along with View Models -are- Presentation Layer

MVC模式 - 可 - 数据访问层和业务层甚至是服务层

MVC Models - could be - Data Access Layer or Business Layer or even Service Layer

推荐答案

我看到 Asp.Net MVC部分只能作为查看(或presentation)部分整个应用程序的。

I see the Asp.Net MVC part only as the view (or presentation) part of the whole application.

我的问题是如何构建的应用程序以适当的方式挣扎过。结果
洋葱建筑我听到关于 这里 (特别是图像发现这里),我的解决方案看起来是这样的:

I struggled too with the problem how to structure the app in a proper way.
Following the Onion Architecture I heard about here (and especially the image found here), my solution looks this way:


  • Project.Core 结果
    业务逻辑/服务实现中,实体,接口必须由其他项目中实现(即IRepository,IAuthenticationService,...)

  • Project.Data 结果
    DB连接 - 在我的情况NHibernate的仓库和实体映射到这里。
    器物的数据的Project.Core的γ-接口

  • Project.UI.Web 结果
    在Asp.Net MVC(presentation)项目 - 它的导线整个应用程序一起结果
    对接口的Project.Core和电线他们(那些Project.Data)与像温莎城堡的一些DI框架的实现。

  • Project.Core
    Business logic/services implementations, entities, interfaces that must be implemented by the other projects (i.e. "IRepository", "IAuthenticationService",...)
  • Project.Data
    DB connection - in my case NHibernate repositories and entity-mappings go here. Implements data-interfaces of Project.Core
  • Project.UI.Web
    The Asp.Net MVC ("presentation") project - it wires the whole app together.
    Has implementations for Interfaces in Project.Core and wires them (and those from Project.Data) up with some DI framework like Castle Windsor.

Project.UI.Web遵循以下约定:

Project.UI.Web follows the following conventions:


  • 及其模式只(!)的ViewModels

  • 的意见消耗他们的拥有视图模型(单视图一个视图模型)

  • 控制器只需为验证输入,转换入的域对象(如业务逻辑 exacly一无所知的ViewModels )和委托真正的工作(业务逻辑)的业务服务。

  • its models are only(!) viewmodels
  • the views consume their own viewmodel (one-view-one-viewmodel)
  • the controllers just need to validate the input, transforms it into domain objects (as the business logic knows exacly nothing about viewmodels) and delegate the real work (business logic) to the business services.

摘要:结果
如果按照这个模式是有帮助的重点Project.Core 真正的应用。它不担心数据的真正的持久性也不关心它是如何获得presented。这只是关于如何到做它。但它奠定了规则和合同(接口),其他项目必须提供实现。

Summary:
If you follow this model it's helpful to focus on Project.Core: that is the real application. It doesn't worry about the real persistence of data nor cares about how does it get presented. It's just about "how-to-do-it". But it's laying out the rules and contracts (interfaces) the other projects must provide implementations for.

我希望这有助于你如何布置一个Asp.Net MVC应用程序!

I hope this helps you with how to layout an Asp.Net MVC application!

LG结果
warappa

Lg
warappa

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

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