什么类型的架构是这样叫什么? [英] What type of architecture is this called?

查看:101
本文介绍了什么类型的架构是这样叫什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我目前正在开发Web应用程序(ASP.NET MVC),我们已经制定了以下结构:

For the web application (ASP.NET MVC) I'm currently developing, we have the following architecture in place:


  • 数据访问层:逻辑持久化数据到任意分贝

  • :数据模型

  • 服务层:业务逻辑(例如订单处理,客户管理等)

  • 控制器:消耗服务和提供/从查看
  • 接收数据/
  • 查看:为用户
  • 用户界面
  • Data Access Layer: Logic for persisting data to an arbitrary db
  • Domain: The data model
  • Service Layer: Business logic (e.g. order processing, account management, etc.)
  • Controller: Consumes services and provides/receives data to/from the View
  • View: The user interface for the user

在本质上,我拿着模式键,把它分解成的 DAL 服务层。我觉得肥了模型中的所有逻辑让我的code过于复杂。此外,我觉得它让我的前preSS我的业务逻辑清晰未做控制器做太多的工作。

In essence, I took the Model and split it up into the DAL, Service Layer and Domain. I felt that stuffing all the logic within the Model made my code overly complicated. Furthermore, I felt that it let me express my business logic cleanly without making the controller do too much work.

那么我的问题是:什么是这种架构的名为

My question then is: What is this type of architecture called?

作为一个次要的问题:这类型的结构是否合理?如果不是这样,我做错了什么?

As a secondary question: Does this type of architecture make sense? If not, am I doing something wrong?

推荐答案

您即将DDD在正确的轨道上取决于如何瘦/厚域和放大器;服务层。 DDD说,知识(即业务逻辑)应嘎吱嘎吱到域模型。移动数据访问担忧的是DAL与DDD线,但我想出来搬家业务逻辑放到一个服务层是没有的。如果你有一个薄域数据模型层(多为实体)和厚服务层(多为商业逻辑),您可能有一个的贫血域

You are on the right track about DDD depending on how thin / thick the domain & service layers are. DDD says that the knowledge (i.e. business logic) should be crunched into the domain model. Moving data access concerns to the DAL is in line with DDD, but I think moving business logic out into a Services Layer is not. If you have a thin Domain "data model" layer (mostly for entities) and a thick Services layer (mostly for "business logic"), you may have an anemic domain.

此外,还有技术上DDD没有服务层。有可能是一个应用层,但它应该是薄的,并且只负责应用流/管理域类的寿命。实际上,这就是控制器在.NET MVC,管理网络的HTTP的情况下应用程序流。

Also, there is technically no "Service Layer" in DDD. There may be an "Application Layer", but it should be thin, and only be responsible for application flow / managing domain class lifetimes. This is essentially what Controllers do in .NET MVC, manage application flow in the context of web http.

如果所有馅模型中的逻辑,使你code过于复杂,我很想用过于复杂听你的意思的例子。你可能会正确地建模复杂的域名,或者有一个你本来可以去DDD模式,以uncomplicate事情的机会。我会说,你已经在你的问题中列出它,拱不DDD。我只想把它称为分层架构,但那是因为我preFER使用术语一级说起物理弓,只有当。然而,你的逻辑架构是分层的。

If stuffing all of the logic within the Model made your code overly complicated, I'd be interested to hear examples of what you mean by "overly complicated". You could be correctly modeling a complex domain, or there are chances you could have gone to DDD patterns to uncomplicate things. I would say as you have listed it in your question, the arch is not DDD. I would just call it "Layered architecture", but that's because I prefer to use the term "tier" only when talking about physical arch. However, your logical architecture is layered.

我真的很喜欢达林挂洋葱拱在他的回答。我成为它的忠实粉丝,我觉得这不是独家DDD在所有。如果你的code使用依赖注入来解决接口与依赖实现运行时,你可能有洋葱拱的形式。例如,你定义在你的DAL任何接口?在运行时解决这些接口的实现?

I really like that Darin linked to Onion arch in his answer. I'm becoming a big fan of it, and I find it's not exclusive to DDD at all. If your code uses dependency injection to solve interface dependencies with runtime implementations, you may have a form of onion arch. For example, do you define any interfaces in your DAL? Are implementations of those interfaces solved at runtime?

下面是一个拱形我开始我的新项目中使用的一个例子。这是洋葱+ DDD的组合:

Here is an example of an arch I am starting to use in my new projects. It's a combination of onion + DDD:


  • API 项目/组件:通用接口,枚举,类和所有其他层中使用扩展方法。不必单独从域,但可能。

  • API Project/Assembly: generic interfaces, enums, classes, and extension methods used by all other layers. Need not be separate from Domain, but may.

项目/组件:所有实体和商业逻辑。只依赖于 API。采用DDD模式,如工厂,服务,规范,资料库等,还包含未在API中定义多个域专用接口。

Domain Project/Assembly: all entities and business logic. Depends on API only. Uses DDD patterns like factory, service, specification, repository, etc. Also contains more domain-specific interfaces which are not defined in the API.

默认地将Impl 项目/组件:在定义接口的实现API 。这就是EF的DbContext的实施,以及之类的东西记录,电子邮件发送等。所有这些实现都依赖注入,所以理论上讲,你可以有几个默认地将Impl项目/组件。

Impl Project/Assembly: implementations of interfaces defined in API and Domain. This is where the EF DbContext is implemented, as well as things like logging, email sending, etc. All of these implementations are dependency-injected, so technically you could have several Impl projects / assemblies.

UI 项目/组件:这是MVC项目。控制器直接使用域面,并没有通过应用程序或服务层去。在工厂,服务储存库等的任何接口的依赖关系,被注入通过使用MVC IOC(构造注射)控制器的域。

UI Project/Assembly: This is the MVC project. Controllers consume the domain surface directly, and do not go through an application or service layer. Any interface dependencies in factories, services, repositories, etc, are injected into the domain by the controller using MVC IoC (constructor injection).

我把一个API层的核心,但你可以在API和域项目合并成一个。无论哪种方式,洋葱的大肉的部分是域名,它有内部的层次感。例如服务可能依赖于工厂,这取决于存储库,它依赖于实体。

I placed an API layer at the very core but you could combine the API and Domain projects into one. Either way, the big meaty part of the onion is the Domain, and it has internal layering. For example Services may depend on Factories, which depend on Repositories, which depend on Entities.

该项目的默认地将Impl就是你看到的巴勒莫图中的基础设施蝉翼。它是在与UI沿外边缘,并且不包含特定领域的知识。它知道如何发送电子邮件,存储/使用EF等,如果你想检索数据,可以有超过1这些 - 例如1默认地将Impl进行数据访问,1默认地将Impl处理邮件等。

The Impl project is what you see as the "Infrastructure" onion skin in Palermo's diagram. It is at the outer edge along with the UI, and contains no domain-specific knowledge. It knows how to send email, store/retrieve data using EF, etc. If you want, you can have more than 1 of these -- for example 1 Impl for data access, 1 Impl for dealing with mail, etc.

MVC有控制器和视图,并集中在用户界面和Web应用程序流。任何需要特定领域的知识被委派到该域和域类构造器注入到控制器。这意味着域类构造函数的任何注入接口由IoC容器自动解决。

MVC has the Controllers and Views, and concentrates on the UI and web application flow. Anything that requires domain-specific knowledge is delegated out to the domain, and domain classes are constructor injected into the controller. This means any constructor-injected interfaces in domain classes are resolved automatically by the IoC container.

最后一点,对API中定义和域类的接口编程意味着你可以单元分别从MVC项目测试域项目。

As a final note, programming against interfaces defined in the API and Domain classes means you can unit test the domain project separately from the MVC project.

这篇关于什么类型的架构是这样叫什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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