在asp.net的MVC模型3个区域 [英] Models in asp.net mvc 3 areas

查看:107
本文介绍了在asp.net的MVC模型3个区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何组织模式在多个领域?我试图组织code。使用领域。我使用的 Visual Studio 2010的前preSS ,该项目是在 asp.net MVC3 code优先开发是用过的。所有的指导和参考互联网上大约只有约车型控制器和路线,但什么谈判?更多precisely,我找周围的建议:


  1. 在一个区域模型文件夹将包含自己的类,所以在这里
    应的DbContext放在哪里?我已经有一个的DbContext类
    包含根模型文件夹多个dbset条目。我可以吗
    有多个的DbContext存储在同一个数据库的数据?

  2. 我已经通过asp.net mvc的便携式领域的项目了
    mvccontrib,但它仍然在asp.net MVC2,但是是唯一的出路
    围绕构建插件/组件asp.net MVC 3?

  3. 除了区/便携式领域,有没有更好的方式来组织
    code是这样一种方式,新功能可以是简单的下降入,
    没有做现有code太多的变化?看起来领域
    有前途的,但我无法弄清楚车型应该如何
    放置。

  4. 是地区不仅有利于控制器和视图分离?


解决方案

  1. 领域仅用于浏览模式分离不错。

一个地区的注册code是朝着什么是用于地区良好的暗示 - 分离出的路线和访问特定的控制器。 (想想逻辑的用户界面单元)。组织您code,命名空间是首选的工具。

也许看像一把umbraco,果园甚至N2CMS,看看他们是如何管理扩展。

How to organize models in multiple areas ? I am trying to organize code using areas. I am using visual studio 2010 express , the project is on asp.net mvc3 and code-first development is used. All the tutorial and reference over internet only talks about controllers and routes, but what about models ? more precisely, I am looking for suggestions around :

  1. The model folder in an area will contain its own classes, so where should the dbcontext be placed ? I already have an dbcontext class containing multiple dbset entries in the "root" model folder. Can i have multiple dbcontext storing its data in the same database ?
  2. I have gone through asp.net mvc portable areas project by mvccontrib, but its still in asp.net mvc2, but is that the only way around for building plugins/components in asp.net mvc 3 ?
  3. Apart from areas/portable areas, is there any better way to organize code is such a way that new features can be simply "dropped-in", without doing too much changes in existing code ? Areas looks promising but i am not able to figure out how models should be placed.
  4. Are areas only good for controller and view separation ?

解决方案

  1. Areas are only good for view model separation.

The registration code of an area is a good hint towards what areas are used for - separating out routes and access to specific controllers. (Think logical user interface units). For organising your code, namespaces are the tool of choice.

Perhaps look at something like Umbraco, Orchard or even N2CMS to see how they manage extensions.

这篇关于在asp.net的MVC模型3个区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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