简体   繁体   English

在业务或数据层中编写逻辑

[英]Writing Logic in Business or Data Layer

I am using a three layered architecture in my web application. 我在Web应用程序中使用了三层体系结构。 I am writing all the MS SQL Server database related codes in the Data Layer and now there is a requirement to read lots of data from Excel, CSV and other spreadsheet files. 我正在数据层中编写所有与MS SQL Server数据库相关的代码,现在需要从Excel,CSV和其他电子表格文件中读取大量数据。 I am using the OleDbConnection, OleDbCommand, OleDbDataReader to read all the contents from the spreadsheet files that are uploaded by the user. 我正在使用OleDbConnection,OleDbCommand,OleDbDataReader从用户上传的电子表格文件中读取所有内容。 There is a debate regarding where I should write the required code, In the Business Logic layer or Data Layer? 关于在业务逻辑层还是数据层中应该在哪里编写所需代码的问题,存在争议。 My assumption is like since reading from the spreadsheet does not have anything to do with our MS SQL Server Db and so I thought of writing it in the Business Logic Layer. 我的假设就像是因为从电子表格读取内容与我们的MS SQL Server Db没有任何关系,所以我想到了在业务逻辑层中编写它。

Is it a right decision? 这是正确的决定吗? Any thoughts? 有什么想法吗?

Data Layer. 数据层。 Actually it's still a data stream. 实际上,它仍然是数据流。 You should treat it as such Your business layer, normally, should not even know from where data comes. 您应该这样对待它。通常,您的业务层甚至都不应该知道数据来自何处。

I would rather why don't you build multiple projects in the solution for a united Data Access Layer. 我宁愿为什么不在解决方案中为统一数据访问层构建多个项目。 Theoretically you will still be designing a three-tier architecture, but with code disparity for high manageability and scalability. 从理论上讲,您仍将设计一个三层体系结构,但是代码之间存在差异,因此具有较高的可管理性和可伸缩性。 Here's how the architecture tree look like: 这是架构树的样子:

  1. Application Logic [Presentation Layer] 应用逻辑[表示层]
  2. Business Logic Layer 业务逻辑层
  3. Data Access Layer [Abstract Layer for communication with BL] 数据访问层[与BL通信的抽象层]
    • SQL Server DAL SQL Server DAL
    • Excel DAL Excel DAL
    • Access DAL 存取DAL
    • any other DAL... 其他任何DAL ...

I'm sure this would work fine with your architecture. 我敢肯定,这将适合您的体系结构。

Best option to extract or save data from any source is to implement it in data layer. 从任何来源提取或保存数据的最佳选择是在数据层中实现它。 Then pass this data to business layer to apply business logic/business rules. 然后将此数据传递到业务层以应用业务逻辑/业务规则。 Keep data access & storage transparent to business layer. 使数据访问和存储对业务层透明。

Some of the benefits: 1. This is to decouple the future scalability & extensibility. 其中的一些好处:1.这是将未来的可伸缩性与可扩展性脱钩。 If you need to change excel data source to a RDBMS or any other type of file then you don't need to change any business logic. 如果您需要将excel数据源更改为RDBMS或任何其他类型的文件,则无需更改任何业务逻辑。 Only data access logic would be changed. 仅数据访问逻辑将被更改。 Similarly if you need to add more business rules or remove some then you don't need to change the data access layer. 同样,如果您需要添加更多业务规则或删除某些业务规则,则无需更改数据访问层。 2. If you need to merge data from tow data sources then you can do it easily transparent to business layer 2.如果您需要合并来自两个数据源的数据,则可以轻松地使它对业务层透明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM