是否有针对 ASP.NET MVC 生产应用程序的建议解决方案结构

发布于 2024-08-26 12:26:23 字数 501 浏览 8 评论 0原文

一般来说,我不喜欢将代码(基类或数据访问代码)保留在 ASP.NET 站点的 App_Code 目录中。我通常会将这些内容提取到 MySite.BusinessLogic & 中。分别是MySite.DataAccess DLL。

我想知道我是否应该对 ASP.NET MVC 做同样的事情。

沿着

  • MySite.Common - DLL - (基于 .NET 系统 Dll 的基本功能)
  • 组织解决方案会更好吗MySite.DAL - DLL - (DataAccessLayer 和 DBML 文件)
  • MySite.Models - DLL - (MVC模型,例如存储库类)
  • MySite.Controllers - DLL(使用模型的 MVC 控制器)
  • MySite - ASP.NET MVC 站点。

或者我错过了一些东西......大概,我会失去一些好的东西(添加视图,转到控制器,已添加的上下文菜单项)

In general, I don't like to keep code (BaseClasses or DataAccess Code) in the App_Code directory of an ASP.NET Site. I'll usually pull this stuff out into a MySite.BusinessLogic & MySite.DataAccess DLL's respectively.

I'm wondering should I be doing the same for ASP.NET MVC.

Would it be better to Organise the solution something along the lines of

  • MySite.Common - DLL - (Basic Functionality built on .NET System Dlls)
  • MySite.DAL - DLL - (DataAccessLayer & DBML Files)
  • MySite.Models - DLL - (MVC Models e.g. Repository Classes)
  • MySite.Controllers - DLL (MVC Controllers which use Models)
  • MySite - ASP.NET MVC Site.

Or am I missing something... presumably, I'll lose some of the nice (Add View, Go To Controller, context menu items that have been added)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

独守阴晴ぅ圆缺 2024-09-02 12:26:23

我只使用 MVC 完成了几个项目,但使用您的命名结构,我们执行了以下操作:

  • MySite.Common - DLL -(基于 .NET 系统 Dll 构建的基本功能)
  • MySite.DAL - DLL -(DataAccessLayer & DLL)
    DBML 文件和存储库模型)
  • MySite.Models - 将此作为一部分包含在内
    MVC Web 应用程序的一部分,并且只有
    特定于视图的模型没有
    始终将每个映射一对一
    存储库模型。
  • MySite.Controllers - 作为一部分包含在内
    MVC 应用程序,但可以链接到业务层
  • MySite - MVC 应用程序。

因此,最终我的 MVC 解决方案中有以下项目:

  • MVC Web 应用程序 - 包含控制器、用于将 DAL 数据映射到的视图模型。
  • 通用 - 可在其他应用程序中使用的功能
  • DAL - 包含所有与数据访问相关的数据,包括包装类
  • BL - 可选,具体取决于它是否需要大量业务特定逻辑
  • 测试

编辑:我的 DAL 始终输出包装对象(如果使用 Linq2Sql,那么我将自动生成的类直接映射到 DAL 中的类)。 MVC 应用程序中存在的唯一类是表示视图的容器,主要用于将数据传递到视图。

如果您的移动应用程序使用类似的视图,我不会尝试重复使用 MVC 应用程序视图中的相同类。您总是需要管理一些细微的差异,并且您应该能够仅使用 DAL 类来映射到您的移动视图,该视图遵循将视图类本地化到应用程序的模式。

I have only done a few projects using MVC but using your naming structure we did the following:

  • MySite.Common - DLL - (Basic Functionality built on .NET System Dlls)
  • MySite.DAL - DLL - (DataAccessLayer &
    DBML Files and Repostiory Models)
  • MySite.Models - included this as part
    of the MVC web app and only had
    models specific to views that did not
    always map one to one for each
    repository model.
  • MySite.Controllers - included as part
    of MVC app but could link to a Business Layer
  • MySite - MVC app.

So in the end had the following projects in my MVC solution:

  • MVC Web App - contains controllers, view models to map DAL data to.
  • Common - functionality that could be used in other apps
  • DAL - contained all the data access related data including the wrapper classes
  • BL - optional depending if it required a lot of business specific logic
  • Tests

EDIT: My DALs alway output wrapped objects (if using Linq2Sql then I map the autogenerated classes to my classes in the DAL directly). The only classes that exist in the MVC app are containers that represent the viwes and mainly used to pass data to the views.

If your mobile app is using similar views I wouldn't try and re-use the same classes from your MVC app views. There is always slight differences that you will need to manage and you should be able to just use the DAL classes to map to your mobile views which follows the pattern of keeping the view classes localized to the app.

音盲 2024-09-02 12:26:23

在大多数情况下,以下结构工作正常:

  • MySite.BusinessLogic(控制器、模型、存储库...)
  • MySite.BusinessLogic.Tests(控制器、模型、存储库...的单元测试)
  • MySiteA(视图、静态内容)
  • MySiteB (视图、静态内容)

MySiteA 和 MySiteB 可能是同一站点的两种形式,重用业务逻辑中的功能。

从性能角度来看,与许多小型组件相比,您应该更喜欢较少的大型组件。

In most cases the following structure works fine:

  • MySite.BusinessLogic (Controllers, Models, Repositories, ...)
  • MySite.BusinessLogic.Tests (unit tests for controllers, models, repositories, ...)
  • MySiteA (Views, Static Content)
  • MySiteB (Views, Static Content)

MySiteA and MySiteB might be two flavors of the same site reusing functionality from the business logic.

From performance perspective you should prefer fewer larger assemblies than many small assemblies.

薄情伤 2024-09-02 12:26:23

我们做的事情有点不同

  • [数据库名称].Database.DLL(特定数据库的 DBML 文件)
  • [数据库名称].Services.[问题域].DLL(包含模型、服务和存储库)
  • [数据库名称].Services .[问题域].Tests.DLL
  • [数据库名称].Services.DLL(当上述所有内容都很好地适合单个服务项目时)
  • [数据库名称].Services.Tests.DLL
  • [问题域].Services.DLL(业务逻辑)按问题域)
  • [问题域].Services.Tests.DLL
  • Web.Framework.DLL(可重用的 ASP.NET 和 MVC 组件)
  • Web.Framework.Tests.DLL
  • MySite.Web.DLL(包括 ViewModel 的 MVC 应用程序)
  • MySite.Web .Tests.DLL

我们这样做是因为我们有多个连接的数据库和数据服务。根据问题域的不同,同一数据库可能会使用不同的模型集进行访问,但有时共享相似的名称。

在服务模块中,我们将具有以下结构

  • \Models
  • \Repositories
  • \Services
  • \etc。

We do things a bit different

  • [Database Name].Database.DLL (DBML files for a specific database)
  • [Database Name].Services.[Problem Domain].DLL (which contains models, services and repositories)
  • [Database Name].Services.[Problem Domain].Tests.DLL
  • [Database Name].Services.DLL (when everything above fits nicely in a single service project)
  • [Database Name].Services.Tests.DLL
  • [Problem Domain].Services.DLL (business logic by problem domain)
  • [Problem Domain].Services.Tests.DLL
  • Web.Framework.DLL (reusable ASP.NET & MVC components)
  • Web.Framework.Tests.DLL
  • MySite.Web.DLL (MVC application including ViewModels)
  • MySite.Web.Tests.DLL

We do this because we have multiple databases and data services that we connect to. And depending on the problem domain the same database might be accessed with a different set of models but sometimes sharing similar names.

Within a Services module we'll have the following structure

  • \Models
  • \Repositories
  • \Services
  • \etc.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文