业务层(BLL)数据访问层(DAL)和UI之间共同的结构? [英] Common structures between business layer (BLL) data access layer (DAL) and UI?

查看:220
本文介绍了业务层(BLL)数据访问层(DAL)和UI之间共同的结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我所有的层BLL,DAL和UI来共享类(混凝土或接口)。

这真的是一个不好的做法?

我preFER不要从我的DAL方法返回的DataTable,而是返回了BLL可以直接使用的对象。

我想有一个单独的VS项目的类的所有层都应该知道这一点。

例如:我想定义所有层应该知道的很多类。用户界面应当能够接收大量的类,以显示或使可能为用户提交了很多以进行处理。另外DAL应该能够查询与很多类数据库,并返回它们。 BLL,另一方面应该得到这些地段和应用业务规则到他们。

如果这是完全错误有什么选择?

解决方案
  

我想我所有的层BLL,DAL和UI来共享类(混凝土或   接口)。

这取决于类的类型。如果你需要他们的所有访问公共域的实体,那么肯定。

最重要的部分是你允许这些层做这些类。您的客户端/ UI层不应该是能够修改域实体(和坚持他们),而无需通过一些集中的业务逻辑。这意味着你的DAL不应该是你的用户界面访问,但它们都可以共享公共实体,接口,等...

一个常用的方法是这样的:

  

用户界面 - > BLL - > DAL - >持久性存储(DB,文件,等...)

每个这些层的可以访问commmon类。只要用户界面无法直接访问DAL,你应该没问题。你有几个选择这样的:

  • 请访问的BLL通过服务(WCF,等...)
  • 把DAL和BLL在同一个项目,使DAL内部所以只有BLL可以访问它

您最终的东西,如:

  

用户界面 - >服务 - > BLL - > DAL - >持久性存储(DB,文件,等...)

我会强烈建议的企业应用架构通过Martin Fowler的模式。它将为您提供分层你的应用程序了良好的基础。

  

我preFER不要从我的DAL方法,而是返回数据表   返回对象BLL可以直接使用。

这是个好主意。这是 ORM 的想法开始发挥作用。该DAL通常会知道如何与数据库,和DAL也将知道如何转换DB-特定结构到你的域模型。域的实体进入,并背出,该DAL。在DAL层,领域实体被持久化数据时转换为DB-特定结构。而相反的情况:当BLL请求数据时,DAL检索数据并将其转换为域enties传递回来之前

I want all my layers BLL ,DAL and UI to share classes (concrete or interfaces).

Is this really a bad practice?

I prefer not to return datatables from my DAL methods but instead to return objects that BLL can use directly.

I want to have a separate VS project with the classes that all layers should know about.

Example: I want to define a lot class that all layers should be aware of. UI should be able to receive lot classes in order to display or make possible for the user to submit a lot to be processed. Also DAL should be able to query the db with lot classes and return them. BLL on the other hand should get these lots and apply business rules onto them.

If this is completely wrong what are the alternatives?

解决方案

I want all my layers BLL,DAL and UI to share classes (concrete or interfaces).

It depends on what type of classes. If you need them all to access common domain entities, then sure.

The important part is what you allow those layers to do with those classes. Your client/UI layer shouldn't be able to modify the domain entities (and persist them) without going through some centralized business logic. This means your DAL shouldn't be accessible by your UI, although they can both share common entities, interfaces, etc...

A common approach is something like this:

UI -> BLL -> DAL -> Persistence storage (DB, file, etc...)

Each of those layers can access commmon classes. As long the UI can't directly access the DAL, you should be okay. You have a couple of options for this:

  • Make the BLL accessible through a service (WCF, etc...)
  • Put the DAL and BLL in the same project and make the DAL internal so only the BLL can access it

You end up with something like:

UI -> Service -> BLL -> DAL -> Persistence storage (DB, file, etc...)

I would strongly recommend Patterns of Enterprise Application Architecture by Martin Fowler. It will provide you with a good foundation for layering your application.

I prefer not to return datatables from my DAL methods but instead to return objects that BLL can use directly.

That's a good idea. This is where the idea of ORM comes into play. The DAL will typically know how to talk to the DB, and the DAL will also know how to convert DB-specific structures into your domain model. Domain entities go into, and back out of, the DAL. Within the DAL, domain entities are converted to DB-specific structures when persisting data. And the reverse happens: when the BLL requests data, the DAL retrieves the data and converts it to domain enties before passing it back out.

这篇关于业务层(BLL)数据访问层(DAL)和UI之间共同的结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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