在我的 API 中使用 BLL 函数而不引用 DAL [英] Use BLL functions without reference the DAL in my API

查看:26
本文介绍了在我的 API 中使用 BLL 函数而不引用 DAL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3 个项目 (C#) API、BLL 和 DAL.DAL 引用 DAL,API 引用 BLL.

I have 3 project (C#) API, BLL and DAL. The DAL reference the DAL and the API reference the BLL.

在我的 API 中,我需要使用所有 CRUD 函数,但我无法使用我的 BLL 中的函数,因为 VS 说类型blabla"是在未引用的程序集中定义的.您需要添加引用 (DAL)",但我不想在 API 项目中引用 DAL.有没有办法在不使用我的 DAL 项目的情况下做到这一点?

In my API I need to use all the CRUD functions but I can't use the function from my BLL because VS said that "The type "blabla" is defined in a assembly that is not referenced. You need to add the reference (DAL)" but I don't want to referenced the DAL in API project. Is there a way to do it without use my DAL project ?

推荐答案

在我看来,您试图实现的是构建项目的好方法.我也在做同样的事情;只是很小的区别,我将在下面解释.在 API 中不引用 DAL 可确保每次调用 DAL 仅通过 BLL.这是必要的,因为我想把我所有的数据处理逻辑放在一个地方.如果是分布式的,很难定位问题.

In my view, what you are trying to achieve is good way to architect the project. I am also doing same; just small difference that I will explain below. Not referencing DAL in API makes sure that every call to DAL is only through BLL. This is necessary because I want to put my all data processing logic at one place. If it is distributed, it is hard to locate issues.

我有四个项目:

  1. Utils(你的blabla"的东西放在这里)[没有参考]
  2. DAL(您的数据库资料放在这里)[参考工具]
  3. BLL(您的逻辑内容放在这里)[如果需要,请参考 DAL 和 Utils]
  4. Api(您的 API 内容在此处)[如果需要,可参考 BLL 和 Utils]

这是一种方式参考链.<代码>DAL =>BLL =>API.逆序的引用不应该存在.Utils 应该是常见的东西,比如实体声明、异常、枚举应该去的地方.

This is one way reference chain. DAL => BLL => API. References in reverse order should not exist. Utils should be common stuff where common things like Entity declarations, Exceptions, Enums should go.

注意:即使您没有在 API 中引用 DAL,您也必须部署它.

Note: Eventhough you are not referencing the DAL in API, you have to deploy it.

为了避免在 API 中使用 Utils,您可能需要再添加一层 DTO 并将它们映射到实体.请参阅我的其他问题.

To avoid using Utils in API, you may need to add one more layer of DTOs and map them with Entities. Refer my other question on same.

这篇关于在我的 API 中使用 BLL 函数而不引用 DAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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