ASP.NET 3层/ 3层架构问题。 [英] ASP.NET 3-Tier / 3-Layer architecture question.

查看:106
本文介绍了ASP.NET 3层/ 3层架构问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,



只是刚刚注册了这个网站,但我之前读了很多文章,发现它真的很有用,所以谢谢你! br $>


我目前正在攻读计算机科学学位的最后一年,并正在研究我的最终项目和论文。我将使用ASP.NET Web Forms和C#创建一个3层项目 - 我不能真正称之为3层,因为它很可能永远不会托管在我本地PC以外的任何其他地方进行测试,因为它是仅限目的。



我的主要问题是:



从我的理解,3的想法-Layer是BLL引用DAL,UI引用BLL来创建完全分离的关注点。但是我在一些教程之后做了一个小的模拟项目,所以得到了3-Layer的悬念,大多数基础教程仍然需要UI和BLL之间的引用。



例如在我创建的项目中,这是一个非常基本的产品和类别类型的电子商务系统,我在DAL中创建了Product和ProductDAL类,然后是BLL中的ProductBLL类。使用这个设置,只使用一个数据库表(暂时忘记类别),BLL似乎只作为UI和DAL之间的一种接口,方法与DAL中的方法完全相同,只调用DAL版本。



问题是要通过BLL访问DAL,我必须将一个Product对象传递给BLL方法参数,这意味着创建一个Product对象首先在UI中,这意味着从UI引用DAL。这是正确的做事方式吗?



我可以通过在BLL中创建一个采用适当字段的方法来解决这种简单的情况。字符串和整数以创建Product对象并将其返回到AddProduct方法。但是,当涉及到将不同的产品属性绑定到UI中的标签时,我仍然需要访问Product对象。



基本上,我是否需要加载BLL中的方法访问产品对象的属性?如果没有,实际上会采用什么样的方法,你能给我一些在这种产品场景中可能出现在BLL中的方法的例子吗?



谢谢提前,如果之前有人问过道歉 - 我确实阅读了很多关于3层架构的帖子,但大多数都非常基本,只能访问一张桌子。



干杯,

Stu。

Morning,

Only just signed up to this site but I have read a lot of articles previously and found it really useful, so thank you for that!

I am currently studying towards my final year of a Computer Science degree, and working on my final project and dissertation. I will be using ASP.NET Web Forms and C# to create a 3-Layer project - I can't really call it 3-Tier as it will most likely never be hosted on anything other than my local PC for testing as it is for uni purposes only.

My main question is this:

From my understanding, the idea of 3-Layer is that the BLL references the DAL, and the UI references the BLL to create complete separation of concerns. However I have made a small mock up project following a few tutorials so get the hang of 3-Layer, and most basic tutorials still require a reference between the UI and BLL.

For example in the project I have created, which is a very basic Products and Categories type e-commerce system, I have created the Product and ProductDAL classes in the DAL, then the ProductBLL class in the BLL. With this setup, of only using one database table (forget categories for now), the BLL seems to only serve as a sort of interface between the UI and DAL, the methods are exactly the same as those in the DAL and only call the DAL version.

The problem is that to access the DAL via the BLL, I have to pass in a Product object to the BLL method arguments, which means creating a Product object in the UI first, which means referencing the DAL from the UI. Is this the correct way of doing things?

I can get around simple cases like this by creating a method in the BLL that takes the appropriate fields, e.g. strings and ints to create the Product Object and returns it to the AddProduct method. However when it comes to binding different product attributes to labels in the UI, I still need access to the Product object.

So essentially, do I need to make a load of methods in the BLL to access properties of the Product Object? If not, what kind of methods would actually go there, can you give me any examples of methods that may go in the BLL in this kind of Product scenario?

Thanks in advance, and apologies if this has been asked before - I did read through a lot of posts about 3-Layer architecture but most are very basic and only access one table.

Cheers,
Stu.

推荐答案

我遵循的方法是我有4层:UI,BLL,对象和DAL。 UI图层引用BLL和对象图层,BLL引用对象和DAL图层以及DAL引用对象图层。



现在,这个Objects层可以创建表示Product,Customer等对象的类,这些类只保存各个成员属性的数据。使用这种4层方法,您可以轻松地在UI中绑定对象,因为它现在引用了对象(将其视为可供所有图层使用的公共图层)。



从UI到DAL的方法调用传播方面,其他所有内容都保持不变。当然,甚至这种架构也可以改进和重构,就像移动直接处理数据库内容的所有代码,即查询到单独的dll,然后在数据访问对象和对象层中的业务对象之间提供转换机制。希望这会有所帮助。
The approach I follow is I have 4 layers: UI, BLL, Objects and DAL. UI layer references BLL and Objects layers, BLL references Objects and DAL layers and DAL references Objects layer.

Now, this Objects layer is where you create classes that represent objects like Product, Customer etc and these classes would just hold the data for the individual member properties. Using this 4-tier approach, you can easily bind Objects in your UI because it now references Objects (think of this as a common layer that can be used by all the layers).

Everything else remains as is in terms of method call propagation from the UI all the way down to the DAL. Ofcourse even this architecture can be improved and refactored quite a bit like moving all the code that directly handles db stuff i.e. queries to a separate dll and then provide a conversion mechanism between data access objects and your business objects in the Objects layer. Hope this helps.


你好兄弟,



因为你是.Net的新手你有问了很好的问题。以下是您的问题的答案:



步骤1:为您的数据访问层创建一个新的类库项目。 />


Stet 2:
在解决方案中添加一个新的类库项目,并将其命名为ModalLayer。现在把你的模态类放在像'ProductInfo'它只包含属性没有别的确定。例如



Hi bro,

As you are new to .Net you have asked good question. Here is answer for your question step by step:

Step 1: Create a new class library project for your Data Access Layer.

Stet 2 :
Add a new class library project to your solution and name it like ModalLayer. Now put your modal class like 'ProductInfo' it will just contain Properties nothing else ok. e.g.

public class ProductInfo
 {
   //Gets or sets the product id
   public int ProductId {get; set;}

   //Gets or sets the product name
   public string ProductName {get; set;}

 }





现在您已经在ModalLayer中创建了包含ProductInfo类的类,现在您只需要对数据访问层项目进行引用,以便您可以访问数据访问层中的到ProductInfo类。



步骤3:
将另一个类库项目添加到名为ProductBLL的解决方案中,并再次将ModalLayer项目的引用放到可以访问ProductInfo类的ProductBLL项目中。 />


第4步:现在最后创建你的UI项目,如ASP.NET或其他你需要的WPF和其他人。再次在这个项目中引用ModalLayer,你也可以在这里访问ProductInfo类。



但是别忘了将DLL引用到BLL和BLL到UI同样。现在,您可以轻松地将数据从一个层传递到另一个层。



谢谢



Now you have created class in ModalLayer which contains ProductInfo class, now you just need to put a reference to Data Access Layer Project so that you can have access to ProductInfo class in Data Access Layer.

Step 3:
Add one more class library project to your Solution named like ProductBLL and again put the reference of ModalLayer project to ProductBLL project which can access your ProductInfo class.

Step 4: Now at last create your UI project like ASP.NET or whatever you need like WPF an others. And again put reference of ModalLayer in this project and you can also access ProductInfo class here.

But don't forgot to give reference of DLL to BLL and BLL to UI as well. Now you can pass your data easily from one layer to other.

Thanks


这篇关于ASP.NET 3层/ 3层架构问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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