简体   繁体   English

MVC应用程序架构的数据流

[英]Data flow of MVC application architecture

Attempting to validate the approach for data flow in an MVC application that i am cleaning up and streamlining, (after a bit of refactoring) things currently looks like the diagram below (Data flow indicated by arrows). 试图在MVC应用程序中验证数据流的方法,我正在清理和简化(在一些重构之后)当前的事情如下图所示(数据流由箭头指示)。 and some parts are written to access the the repository services jumping over layers. 并编写了一些部分来访问跳过图层的存储库服务。 (Like an HTML helper directly accessing a repository service for lookup data) (就像直接访问存储库服务以查找数据的HTML帮助程序一样)

在此输入图像描述

Few Questions. 几个问题。

  1. Is this a typical design and are there any pitfalls? 这是一个典型的设计,有任何陷阱吗?
  2. Is skipping layers for trivial things acceptable? 是否可以跳过琐碎事物的图层?
  3. The flow of data is it architecturally sound? 数据流在架构上是否健全?
  1. This seems to be a common design. 这似乎是一种常见的设计。 Unfortunately I don't have enough experience to point out pitfalls of the design, as the current project I am on is my first experience with this architecture. 不幸的是,我没有足够的经验指出设计的缺陷,因为我目前的项目是我第一次体验这种架构。

  2. If you say that repository services are being accessed in multiple layers, aren't you missing a few arrows? 如果您说存储库服务是在多个层中访问的,那么您是不是错过了几个箭头? Ideally, you don't want to be accessing your repository from the controller (or a Razor helper) as that makes your code more tightly coupled and muddies your otherwise good separation of concerns. 理想情况下,您不希望从控制器(或Razor帮助程序)访问您的存储库,因为这会使您的代码更紧密地耦合并使您的关注点分散。 However, that isn't to say it is terrible to have some limited repository access in multiple modules. 但是,这并不是说在多个模块中拥有一些有限的存储库访问权限是很糟糕的。 The best practice would be to move these repository calls into your business logic, and pass it on to the controller from there. 最佳实践是将这些存储库调用移动到业务逻辑中,然后从那里将其传递给控制器​​。

  3. The ASP.NET project I'm currently on is using a very similar architecture and we are having success with it. 我目前使用的ASP.NET项目使用的是非常相似的架构,我们正在取得成功。

Seems already quite good. 似乎已经相当不错了。

Typically I have following layering: 通常我有以下分层:

  • Presentation layer : contains MVC web site with models, controllers, views and view models. 表示层 :包含带有模型,控制器,视图和视图模型的MVC网站。
  • Services layer : contains services exposed to everything in presentation layer (in the form of WCF service or web API or even just a class library). 服务层 :包含暴露于表示层中所有内容的服务(以WCF服务或Web API的形式,甚至只是一个类库)。
  • Application layer : contains application logic, in my case these are command and query handlers that use underlying domain model and infrastructure services. 应用程序层 :包含应用程序逻辑,在我的例子中,这些是使用底层域模型和基础结构服务的命令和查询处理程序。
  • Domain layer : domain entities and services, has no dependencies to other layers and contains domain logic. 域层 :域实体和服务,与其他层没有依赖关系,并包含域逻辑。
  • Infrastructure layer : contains infrastructural concerns, like data access, logging etc... 基础设施层 :包含基础设施问题,如数据访问,日志记录等......

To minimize dependencies, I program against interfaces; 为了最小化依赖性,我对接口进行编程; of which the concrete implementation is injected by an IoC container. 其中具体实现由IoC容器注入。 This means that every component is also very testable. 这意味着每个组件也都是非常可测试的。

Your controllers of the presentation layer are thin, and use the services layer only (and infrastructure layer). 表示层的控制器很薄,仅使用服务层(和基础结构层)。

This is a very flexible approach, yet simple enough to work for most types of applications. 这是一种非常灵活的方法,但又足够简单,适用于大多数类型的应用程序。 Also, if you use entity framework, you might want to think about whether you actually need repositories and unit of work. 此外,如果您使用实体框架,您可能想要考虑您是否确实需要存储库和工作单元。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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