BLL和DAL之间的通信 [英] Communication between BLL and DAL

查看:371
本文介绍了BLL和DAL之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案设置:

  • 在DAL(类库)
  • BLL(类库)
  • 通用​​(类库(一些常用的功能 - 枚举,日志,异常,...))
  • 应用程序1(Windows应用程序)
  • 应用2(Windows应用程序)
  • 在Web应用程序(Web应用程序)
  • ...

让我们说我有一个客户实体,它是:

Let's say I have a Customer entity, which is:

  • 在SQL Server中的表
  • 一个CustomerDataTable在DAL
  • 在BLL Customer类
  • 在所有的应用中BLL.Customer类

什么样的​​对象应该BLL和DAL用于通信 - 数据表名单,其中,客户> (例如: )?在第一种情况下,BLL逻辑应该转换客户对象的DataTable并将其发送给DAL。在secod情况下,DAL层应该意识到Customer类,这是在BLL层。但渊源DLL的参考DAL,而不是相反...

What kind of objects should BLL and DAL use for communication - DataTable or List<Customer> (for example)? In first case, BLL logic should transform Customer object to DataTable and send it to DAL. In secod case, DAL layer should be aware of Customer class, which is in BLL layer. But originaly DLL references DAL and not opposite...

我应该把所有的类成单独的组件,它是由所有其他(通用,则BusinessObjects,...)引用?在这种情况下,我可以在我所有的项目中使用Customer类。

Should I put all classes into seperate assembly, which is referenced by all others (Common, BusinessObjects, ...)? In this case I could use Customer class in all my projects.

我应该不屑于独立的DAL和BLL的时候,我知道,只有一个BLL会用我的DAL。在这种情况下,我可以把它们合并起来成为一个项目。

Should I even bother to seperate DAL and BLL when I know, that only one BLL will use my DAL. In this case I could merge them together into one project.

PS - 我读有关数据表,很多人说,我们不应该使用它们。什么是更好的选择?也许是时候了,我要学习一些ORM映射工具:)

PS - I am reading about DataTables and a lot of people say that we shouldn't use them at all. What are better options? Maybe it is time for me to learn some ORM mapping tools :)

推荐答案

在我,你应该有另一个层(单独的DLL)的意见。像域,你会保留所有的实体,如客户。 然后简单地包括在所有更高级别(DAL,BLL,UI等)的层次结构该组件。

In my opinion you should have another Layer (seperate dll). Like "domain", where would you keep all entities like Customer. Then simply include in all higher levels(DAL, BLL, UI and others) in hierarchy this assembly.

采样架构可以是这样的:

Sample architecture can look like this:

(数据库)&LT; - > DAL&LT; - > BL&LT; - >用户界面

(Database) <-> DAL <-> BL <-> UI

和各级,你将有机会获得域层。 DAL应返回列表不是一个DataTable。在某个阶段,你的开发过程中,你可能希望在DAL使用一些OMR像NHibernate的使用也将返回一个列表,大概。

and on all levels you will have access to "domain" layer. DAL should return List not a DataTable. On some stage your development process you may want to use in DAL some OMR like NHibernate with would also return a List, probably.

这篇关于BLL和DAL之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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