I have 3 project (C#) API, BLL and DAL. The DAL reference the DAL and the API reference the BLL.
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 ?
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:
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.