我应该尝试将 asp 控制事件放入 BLL 中吗?

发布于 2024-10-05 06:01:05 字数 252 浏览 3 评论 0原文

最近在学习数据访问层、业务逻辑层和表示层,但还是有一些不太清楚的地方。

我可以将 DAL 和 BLL 与表示层结合使用来获取或设置数据库中的信息。

但我也思考了asp控件事件,以及我应该如何实现它们。

例如,我应该尝试将按钮单击事件放入 BLL 中,还是应该将其留在 aspx 代码隐藏文件中?

如果我应该将它们放入 BLL 中,我将如何做?

我不确定如何使事件调用 BLL 中的方法,因此任何建议将不胜感激。

I have recently been learning about Data Access Layers, Business Logic Layers and Presentation Layers, but I still have a few things that aren't quite clear.

I can use the DAL and BLL with the Presentation Layer to get or set information in a database.

But I also thought about asp control events, and how I should implement them.

Should I, for example, try to put a button click event into the BLL or should I just leave it in the aspx code behind file?

And if I should put them into the BLL how would I go about doing this?

I'm not sure how to make an event call a method which is in the BLL, so any advice would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光磨忆 2024-10-12 06:01:05

鉴于此架构:

演示文稿->业务->数据

任何层都应该只了解其直接右侧的层并对其做出假设。这意味着表示层可以与业务层对话并使用它的 API,但它不应该直接与数据层对话。业务层可以使用数据层的 API,但它永远不应该了解或假设使用它的表示层。显然,数据层不应该了解任何其他层。

如果您遵循这个一般原则,您会发现您的应用程序将变得更简单且更易于维护。

不过,要回答您的问题,按钮单击事件属于表示层 - 将按钮单击事件放入业务逻辑中会模糊两层之间的界限,并会产生不必要的耦合。

Given this architecture:

Presentation -> Business -> Data

Any layer should only know about and make assumptions about the layer to its immediate right. This means that the presentation layer can talk to the business layer and use it's API but it should never talk directly to the data layer. The business layer can use the data layer's API but it should never know about or make assumptions about the presentation layer that consumes it. And obviously the data layer should know nothing about any of the other layers.

If you follow this general principal you will find that your application will be simpler and easier to maintain.

To answer your question though, button click events belong in the presentation layer - putting a button click event into your business logic would blur the lines between the two layers and would create unnecessary coupling.

一念一轮回 2024-10-12 06:01:05

如果事件与业务模型有关,那么您应该在 BLL 中创建一个方法。如果是UI类型的事件,则在后面的代码中处理。因此,例如,如果用户单击按钮来计算运费,则在按钮的单击事件处理程序(后面的代码)中调用 BLL 对象的CalculateShipping() 方法。但是,如果您有一个可以更改页面背景颜色的按钮(我想不出更好的示例),那么您将在后面的代码中完全处理它。

If the event has to do with the business model, then you should create a method in the BLL. If it's a UI type of event, handle it in the code behind. So, for example, if the user clicks a button to calculate the shipping, in the button's click event handler (code behind) call your BLL object's CalculateShipping() method. If, however, you have a button that changes the background color of the page (I couldn't think of a better example) then you would handle that completely in the code behind.

单身狗的梦 2024-10-12 06:01:05

您的 ASPX 代码隐藏文件(表示层)可以直接引用您的 BLL(导致耦合),或者您可以使用更面向服务的方法。这将涉及创建由表示层引用并由业务层实现的接口。在应用程序初始化期间(即在 Global.asax 文件中),您可以通过依赖项注入或其他方法将 BLL 连接到表示层。

Your ASPX code behind file (Presentation Layer) could either have a direct reference to your BLL (results in coupling) or you can use a more service oriented approach. This would involve creating interfaces referenced by your Presentation Layer and implemented by your Business Layer. During application initialization (i.e. in your Global.asax file), you can you connect the BLL to your Presentation Layer via dependency injection or some other approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文