[英]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. 几个问题。
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. 不幸的是,我没有足够的经验指出设计的缺陷,因为我目前的项目是我第一次体验这种架构。
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. 最佳实践是将这些存储库调用移动到业务逻辑中,然后从那里将其传递给控制器。
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: 通常我有以下分层:
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.