在洋葱型架构,应实体交叉外层? [英] In an Onion type architecture, should the entities cross the outer layer?

查看:278
本文介绍了在洋葱型架构,应实体交叉外层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图理解这种新的架构这名称可以是洋葱的建筑,干净的建筑,港口和适配器等。

I've been trying to understand this new kind of architecture which names can be Onion architecture, Clean architecture, Ports and Adapters, etc.

如果我把端口和适配器的抽象,当我适应我的应用程序特定的端口,它是确定为我从我的应用程序里给端口的实体?或者,我总是应该也适应实体,以适应端口?

If I take the abstraction of Ports and Adapters, when I adapt my application for a particular port, is it ok for me to give the port an entity from inside my application? Or am I always supposed to adapt the entities also, to fit the port?

例如:

说我有一个客户实体。我有一个使用我的应用程序的UI。我的用户界面通过一个适配器getCustomerById(123)调用。反过来,我的适配器将通过打电话给我的应用程序,使用注射库有效地检索客户,它会进行某种形式的它,记录格式,而不是,一旦客户准备好了,这是回到我的UI内容。我的问题在这里,我的客户对象被返回是我的UI。这意味着,我的UI已经从我的核心项目,客户类的引用。我的UI然后继续使用该客户对象做的事情,也许改变它的名字等等,并最终再次调用适配器updateCustomer(客户)。

Say I have a Customer entity. I have a UI that uses my application. My UI calls through an Adapter to getCustomerById(123). In turn, my adapter will call through to my application, effectively retrieving a Customer using the injected Repository, and it will perform some sort of formatting on it and logging and what not, once the Customer is ready, it is returned to my UI. My question here is, my Customer object is returned as is to my UI. This means my UI has a reference to the Customer class from my Core project. My UI then goes on using that Customer object to do things, maybe change it's name, etc. and eventually calls the adapter again to updateCustomer(customer).

这是正确的呢?它是确定我的UI使用客户类从我的应用程序的内线核心。或者我应该适应,而不是我的客户到一个新的客户对象,说UICustomer并有我与替代,测绘工作的用户界面来回客户和UICustomer之间适配器级别的?

Is this ok to do? Is it ok that my UI uses the Customer class from inside my application core. Or should I instead adapt my Customer to a new Customer object say UICustomer and have my UI work with that instead, mapping back and forth between Customer and UICustomer at the adapter level?

推荐答案

大问题。我有可能是有用的一个例子。
https://bitbucket.org/jeffreypalermo/onion-architecture

Great question. I have an example that might be useful. https://bitbucket.org/jeffreypalermo/onion-architecture

有关使用核心领域模型对象,简单的应用程序可以就好了。这些都是旨在不必依赖挂他们的触角讨厌的,所以他们的工作非常出色,是相当便携。它们可以在整个层的旅行,而不会引起任何问题。

For simple applications using the Core domain model objects can be just fine. These are designed to not have nasty tentacles of dependencies hanging off of them, so they work very well and are quite portable. They can travel across the layers without causing any issues.

这篇关于在洋葱型架构,应实体交叉外层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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