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

查看:148
本文介绍了使用BLL函数而不在我的API中引用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(您的数据库中的东西放在这里)[library Utils]

  3. BLL(您的逻辑资料在此处)[如果需要,请参考DAL和Utils]

  4. Api(您的API资料在此处)[需要时参考BLL和Utils]

  1. Utils (your "blabla" stuff goes here) [References nothing]
  2. DAL (your database stuff goes here) [References Utils]
  3. BLL (your logic stuff goes here) [References DAL and Utils if needed]
  4. Api (your API stuff goes here) [References BLL and Utils if needed]

这是一种参考链。 DAL => BLL => API 。反向引用不应存在。 实用程序应该很常见,诸如实体声明,异常,枚举之类的常见内容应该出现。

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.

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

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