在架构asp.net mvc的应用程序的建议 [英] advice on architecting asp.net mvc applications

查看:104
本文介绍了在架构asp.net mvc的应用程序的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用ASP.net MVC两年左右,现在,我还在学习结构的应用程序的最佳方式。

I've been using ASP.net MVC for about two years now and I'm still learning the best way to structure an application.

我想扔掉这些想法,我已经收集并看看他们是否在社区可以接受的方式来设计MVC应用。

I wanted to throw out these ideas that I've gathered and see if they are "acceptable" ways in the community to design MVC applications.

这是我的基本布局:


  • 数据访问项目 - 包含所有库类,LINQ到SQL数据上下文,过滤器和自定义业务对象非MS SQL数据库存储库(即LINQ到SQL没有按'T创建)。该库通常只对他们管理的对象基本的CRUD。

  • DataAccess Project - Contains all repository classes, LINQ-to-SQL data contexts, Filters, and custom business objects for non-MS SQL db repositories (that LINQ-to-SQL doesn't create). The repositories typically only have basic CRUD for the object they're managing.

服务项目 - 包含执行业务逻辑服务类。他们从控制器的订单,告诉库做什么。

Service Project - Contains service classes that perform business logic. They take orders from the Controllers and tell the repositories what to do.

UI项目 - 包含视图模型和周围的事物,像ConfigurationManager中的一些包装(单元测试)

UI Project - Contains view models and some wrappers around things like the ConfigurationManager (for unit testing).

主要MVC项目 - 包含控制器和视图,以及JavaScript和CSS

Main MVC Project - Contains controllers and views, along with javascript and css.

这是否看起来是一个很好的方式来构建ASP.NET MVC 2应用程序?任何其他的想法或建议?

Does this seem like a good way to structure ASP.NET MVC 2 applications? Any other ideas or suggestions?

用于所有输出到的意见和投入看法视图模型?

Are view models used for all output to views and input from views?

我俯身使视图模型为需要在视图中显示数据的每个业务对象,使他们有一堆都是字符串属性基本类的路径。这使得处理意见pretty容易。然后,服务层需要从视图模型的业务对象管理映射属性。这是我的一些混乱的根源,因为大多数我见过的MVC / MVC2,除非你需要像一个组合框不使用视图模型的例子。

I'm leaning down the path of making view models for each business object that needs to display data in the view and making them basic classes with a bunch of properties that are all strings. This makes dealing with the views pretty easy. The service layer then needs to manage mapping properties from the view model to the business object. This is a source of some of my confusion because most of the examples I've seen on MVC/MVC2 do not use a view model unless you need something like a combo box.

如果您使用MVC 2的新模型验证,你会不会再验证视图模型对象,而不是担心把验证业务对象属性?

If you use MVC 2's new model validation, would you then validate the viewmodel object and not have to worry about putting the validation attributes on the business objects?

你怎么单元测试这种类型的验证或者我不应该单元测试验证的邮件将被退回?

How do you unit test this type of validation or should I not unit test that validation messages are returned?

谢谢!

推荐答案

有趣的。

有一件事情我做不同的是,我从我的域名项目分拆数据访问我的项目。该领域工程仍然包含了所有的接口,为我的存储库,但我的数据访问项目包含他们的所有具体的实现。

One thing I do differently is that I split off my DataAccess project from my Domain project. The domain project still contains all the interfaces for my repositories but my DataAccess project contains all the concrete implementations of them.

您不想要的东西,如的DataContext 泄漏到您的域的项目。继洋葱架构您的域名不应该有外部的任何依赖基础设施......我会考虑到数据访问有一个,因为它直接连接到数据库。

You don't want stuff like DataContext leaking into your domain project. Following the onion architecture your domain shouldn't have any dependencies on external infrastructure... I would consider DataAccess to have that because it's directly tied to a database.

拆分其关闭意味着我的域名没有任何ORM或数据库的依赖,这样我就可以换出来轻松如果需要的话。

Splitting them off means that my domain doesn't have a dependency on any ORM or database, so I can swap them out easily if need be.

干杯,结果
查尔斯

Cheers,
Charles

诗。什么是您的项目依赖关系是什么样子?我一直想知道往哪里放我的ViewModels。也许一个独立的UI项目是一个好主意,但我不能完全肯定,将如何工作。他们如何通过应用程序的不同的项目层流?

Ps. What does your project dependency look like? I've been wondering where to put my ViewModels. Maybe a separate UI project is a good idea, but I'm not entirely sure how that would work. How do they flow through the different project tiers of your application?

这篇关于在架构asp.net mvc的应用程序的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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