Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
622 views
in Technique[技术] by (71.8m points)

c# - Use BLL functions without reference the DAL in my API

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

enter image description here

enter image description here

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

I have four projects:

  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]

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.

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...