通过多层架构层传递业务实体 [英] Passing business entities through layers in multi layer architecture

查看:234
本文介绍了通过多层架构层传递业务实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我在一个项目开发多层建筑工作作为rel=\"nofollow\">应用架构指南2.0 5层(DAL,BLL,门面,presentation层和公共层)。结果
在这里,我们有由业务组件和业务实体(这是实体产生使用O / R映射器)的业务逻辑层,经常我们需要在presentation层这个实体绑定和presenting数据到用户因此我们这个泡沫最多的实体通过其他层presentation层。

Currently I'm working on a project exploiting multi layer architecture as described in Application Architecture Guide 2.0 with 5 layers(DAL, BLL, Facade, Presentation Layer and Common Layer).
Here we have a Business Logic Layer which consists of Business Components and Business Entities(which are entities generated using an O/R Mapper), regularly we need this entities in our presentation layer for binding and presenting data to the user so we bubble this entities up to the Presentation Layer through other layers.

现在的问题是:结果
它是一个正确的做法? (据我所知根据定义,如果我们都应该分享这些,我们应该把它们放在同一层,所以我们可以在所有层使用它们)。
我们不应该提出这个实体公共层?或者我们应该定义像数据传输对象(DTO的),并通过他们通过层(当然这似乎是多余的)。

Now the question is:
Is it a right approach? (As I know by definition if we are supposed to share these we should place them in Common Layer so we can use them in all layers). Shouldn't we move this entities to common layer? or should we define something like Data Transfer Objects(DTOs) and pass them through the layers(which of course seems redundant).

任何澄清将AP preciated。

Any clarification would be appreciated.

推荐答案

一个适当的分层应用程序通常会使用DTO的,以prevent企业实体被掺假和歪曲以适应其他层,除其他原因的需要。

A properly layered application will generally use DTO's to prevent business entities from being adulterated and distorted to suit the needs of other layers, among other reasons.

不过,在非常小的应用程序,你可以腾出自己DTO映射的负担,有企业实体一路传递到UI。你可以让他们在BLL,这不是戏剧性的,如果所有层都对它的引用。这是不是一个真正的分层应用更多反正因为你那种嘎吱嘎吱的架构成一个大的层。

However, in very small apps you could spare yourself the burden of DTO mapping and have the business entities passed all the way to the UI. You can keep them in the BLL, it's not dramatic if all layers have a reference to it. It is not really a layered application any more anyway since you sort of crunched the architecture into one big layer.

标记塞曼有一个有趣的博客文章。

Mark Seemann has an interesting blog post on this problem.

这篇关于通过多层架构层传递业务实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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