洋葱archicecture依赖在同一层:基础设施和网络通信 [英] Onion archicecture dependencies in the same layer: Infrastructure and Web communicating

查看:160
本文介绍了洋葱archicecture依赖在同一层:基础设施和网络通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计使用ASP.NET MVC应用程序的洋葱架构通过杰弗里描述巴勒莫。

I am designing an ASP.NET MVC application using the Onion Architecture described by Jeffrey Palermo.

这是一个ASP.NET MVC 2.0项目中,我要求所有视图中使用专用视图模型是强类型 - 我们将不会传递域模型我们的意见。我们使用AutoMapper做翻译。 - AutoMapper在基础设施中分离,网络不知道或不关心正在使用AutoMapper

It is an ASP.NET MVC 2.0 project, where I am requiring that all views be strongly typed using dedicated View Models -- we will not be passing domain models to our views. We are using AutoMapper to do the translation -- AutoMapper is isolated in the infrastructure, Web does not know or care that AutoMapper is being used.

目前,我定义Web项目的IViewModelMapping接口 - 仅仅是因为这项服务将由控制器一起使用,它有它自己的视图模型的直接访问。这样的接口可以访问两个域模型(核心)和视图模型(网络)。

Currently, I am defining the IViewModelMapping interfaces in the Web project -- simply because this service will be used by the Controllers and it has direct access to its own View Models. This way the interface can access both the Domain Models (in Core) and the View Models (in Web).

为了提供实际执行的IViewModelMapping接口的,我在基础设施项目,该项目将实际的映射实现隔离到洋葱的Intrastructure创建ObjectMapping命名空间。这样做,这需要基础设施,以对核心和网络的依赖。

In order to provide the actual implementation of the IViewModelMapping interfaces, I created an ObjectMapping namespace in the Infrastructure project, which will isolate the actual mapping implementation to the Intrastructure of the onion. In doing so, this will require Infrastructure to have a dependency on BOTH Core AND Web.

我的问题是:因为这两个项目在技术上对洋葱的郊区(在同一层) - 是一个项目允许有关于该层另一个项目的依赖?有没有人发现任何潜在的缺陷这种设计?

My question is: since both of these projects are technically on the outskirts of the onion (in the same layer) -- is one project allowed to have a dependency on another project in that layer? Does anyone notice any potential pitfalls with this design?

另外一个设计将移动IViewMapper接口插入到核心 - 但这是不可能的,因为核心不具有访问视图模型类。我也可以移动视图模型为核心,但我觉得他们不会属于那里,因为它们是特定的UI层。

An alternative design would be moving the IViewMapper interfaces into Core -- but this would be impossible because Core does not have access to the ViewModel classes. I could also move the view models into Core, but I feel like they would not belong there, since they are specific to the UI layer.

提议的架构如下 - 请注意,基础设施对核心服务器和Web的依赖。网络仍然是孤立,只能访问核心业务逻辑。

The proposed architecture is as follows -- notice that Infrastructure has a dependency on Core AND Web. Web remains isolated and only has access to the Core business logic.

推荐答案

您是正确的,你不想基础设施依赖于UI(网页),但我有时会打破这个规则。

You are correct that you don't want Infrastructure to depend on UI(Web), but I break that rule sometimes.

我反而觉得IViewModelMapping的,创建方法地图IMapper()。然后,该接口可以有可能与视图模型映射,或者只是普通的映射做的实现。无论哪种方式,该接口可以是核心,因为它不是语义上绑定到任何类型的模型

I would think instead of IViewModelMapping, create IMapper with method Map(). Then, the interface can have implementations that might have to do with view model mapping, or maybe just regular mapping. Either way, that interface can be in Core because it is not semantically bound to any type of model.

伟大的图形。我希望我回答你的问题的肉。洋葱架构的总体理念是让你的业务逻辑和模式在应用程序的中间(核心),并尽量向外推你的依赖成为可能。

Great graphic. I hope I answered the meat of your question. The overall philosophy of the Onion Architecture is to keep your business logic and model in the middle (Core) of your application and push your dependencies as far outward as possible.

这篇关于洋葱archicecture依赖在同一层:基础设施和网络通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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