帮助进行有关关注点分离的辩论(数据访问与业务逻辑) [英] Help with debate on Separation of concerns (Data Access vs Business Logic)

查看:104
本文介绍了帮助进行有关关注点分离的辩论(数据访问与业务逻辑)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的同事讨论了某些逻辑是属于数据访问层还是业务逻辑层。

I had a debate with my co-worker on whether certain logic belongs in the data access or business logic layer.

这种情况是BLL需要一些数据来处理。该数据主要存在于数据库中。我们希望缓存这些数据(使用System.Runtime.Caching),以便在后续请求中可以快速使用。这种架构使得DAL和BLL驻留在同一盒子上,并且位于不同的程序集中(同一解决方案中的项目)。因此,不必担心在电线上击中DAL之类的东西。

The scenario is, the BLL needs some data to work with. That data primarily lives in the database. We want to cache that data (using System.Runtime.Caching) so it's quickly available on subsequent requests. The architecture is such that the DAL and the BLL live on the same box and in different assemblies (projects in the same solution). So there is no concern of hitting a DAL over the wire or anything like that.

我的论点是,决定对数据库进行缓存是DAL的问题。业务逻辑层不应该关心数据来自何处,而只关心它获取所需的数据。

My argument is that the decision to hit the cache vs the database is a concern of the DAL. The business logic layer should not care where the data comes from, only that it gets the data it needs.

他的论据是,数据访问层应该是纯和哑的,并且任何决定访问缓存与数据库的逻辑都应该在业务逻辑层。

His argument is that the data access layer should be "pure" and "dumb" and any logic to make that decision to hit the cache vs the database should be in the business logic layer.

在我看来,他的意思是破坏关注点分离,并在目标是使事物保持松散耦合时使各层紧密耦合。我可以看到,如果BLL是一个特定的程序/ ui函数来决定将数据存储到何处,那么BLL可能希望在哪里控制它,但这根本不是这种情况。这只是一个非常简单的缓存方案,其中数据库是主要数据存储。

In my opinion what he's saying is undermining separation of concerns and causing the layers to be more tightly coupled when the goal is to keep things loosely coupled. I can see where the BLL might want to control this if it was a specific program/ui function to decide where to go for data, but that simply isn't the case here. It's just a very simple caching scenario where the database is the primary data store.

有想法吗?

推荐答案

我认为缓存应该在业务层中完成。当您尝试从DAL获取数据时,可以检查高速缓存system.runtime.caching中的数据是否可用,然后使用高速缓存数据,否则从数据库中获取数据。此外,如果您由于某种原因要使缓存无效,可以稍后通过在业务中调用一个函数来实现。

I believe that the caching should be done in the business layer. The moment you try to get the data from DAL, you can check if the data is available in cache system.runtime.caching, then use cache data otherwise fetch data from the database. Moreover if you want to invalidate cache due to some reason, you can do it by calling a function in the business later.

这篇关于帮助进行有关关注点分离的辩论(数据访问与业务逻辑)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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