ASP.NET MVC(域模型、存储库、Fluent、服务 - 我的项目的结构) [英] ASP.NET MVC (Domain Model, Repository, Fluent, Services - Structure for my Project)

查看:22
本文介绍了ASP.NET MVC(域模型、存储库、Fluent、服务 - 我的项目的结构)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 ASP.NET MVC Web 应用程序中,我有:

In my ASP.NET MVC web application, I have:

  • 由 LINQ to SQL 创建的域模型

  • Domain Model, created by LINQ to SQL

存储库,如

UserRepositoryOrderRepository

IQueryable Fluents 作为 IQueryable 扩展方法,例如

IQueryable Fluents as IQueryable Extension Methods such as

public IQueryable GetNewOrders(this IQueryable)

服务如

UserServiceOrderService

实用类和扩展方法如

CryptoUtility(做散列等)和字符串等扩展

CryptoUtility (doing Hashing etc.) and String etc. extensions

每个 MVC 视图的特殊视图模型

ViewModels which are special for each MVC View

ASP.NET MVC 项目本身(控制器、视图)

The ASP.NET MVC project itself (Controllers, Views)

我正在为我的案例寻找最佳的项目结构/组织,尤其是分离成不同的程序集以及这些层之间的依赖关系应该如何.不幸的是,网络资源并没有详细说明这一点.

I'm looking for the best project structure/organization for my case, especially separating into different assemblies and how dependencies should look like between these layers. Web resources unfortunately don't go into good detail about this.

一个提示:目前 Repository、Services、IQueryable Fluents 等直接针对域模型实现工作,我没有为它们定义接口.我认为这是不必要的,但也许这是松耦合所需要的?我的服务有一个接口(例如 IOrderService),我的存储库实现了 IRepository.

One hint: Currently Repository, Services, IQueryable Fluents etc. work directly against domain model implementation, I don't have an interface definition for them. I considered it unnecessary but maybe this is needed for loose coupling? My Services have an interface (e.g. IOrderService), and my repositories implement IRepository<T>.

感谢您对以简洁的方式组织此内容的意见,尤其是哪个层应该取决于什么&大会组织.谢谢!

Appreciate your input on organizing this in a concise manner, and especially what layer should depend on what & assembly organization. Thank you!

推荐答案

我会看 Jeffrey Palermo 关于洋葱架构的文章 这里.这种基本架构适用于任何项目,并允许您将核心项目(域层、持久性等)与 Web 项目分开.

I would look at the article by Jeffrey Palermo on the Onion Architecture here. This basic architecture works well in any project and will allow you to separate your core project (domain layer, persistence, etc.) from your web project.

我们将它与 MVC/StructureMap/FluentNHibernate 一起使用,并取得了巨大的成功.

We use this with MVC/StructureMap/FluentNHibernate and have had great success.

我们最终得到了一个类似于下面的结构.

We end up having a structure similar to the one below.

> trunk
  + build (build scripts)
  + lib (external libraries)
  > src (source code)    
   >> Organization.App (solution name)
     >> Organization.App.Core (code library)
        + Config
        > Domain
          > Model
          > Persistence
          > Queries
          > Services
        > Persistence
        > Services
     >> Organization.App.Web (mvc web app)
        > Assets
          + Images
          + Scripts
          + Stylesheets
        + Controllers
        + Views
        + ViewModels

这是基本的想法.Web 应用程序引用了我们的存储库/工作单元的域实体的核心应用程序.在 google 上查看 这个旧项目代码 类似的例子.关于这一点的重要部分是我们已经能够将新的UI"项目类型添加到相同的解决方案中,并按预期重用我们的核心项目.比如控制台应用或第二个网络应用,或者任何你需要的东西.

That's the basic idea. The web app references the core app for domain entities our repository/unit of work. Check out this older project on google code for a similar example. The great part about this is we have been able to add new "UI" project types to the same solution and re-use our core project as intended. Like a console app or a second web app, or whatever you need.

这篇关于ASP.NET MVC(域模型、存储库、Fluent、服务 - 我的项目的结构)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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