Is there a way in C# to restrict call to indirect referenced library/DLL?

527 views Asked by At

I have a project which is designed in 3-tier architecture. To keep it simple, I will simplify my case in traditionally 3-tiers, Presentation -> Business Logic -> DAL.

I have these 3 tiers in 3 different projects and so that I will have 1 startup executable and 2 DLL finally. However, I found that I can make call from Presentation Layer to DAL Layer even DAL Layer Project is not directly referenced by Presentation Layer Project.

May I know if there any way for me to restrict these indirect references calling? Or any way I can make sure other developer can't make such call?

1

There are 1 answers

3
MatteKarla On

Presenation-project should only reference BusinessLogic-project

BusinessLogic should only reference DAL.

I believe Presentation references both BusinessLogic and DAL.

Make sure that the Presentation.csproj-file looks something like this:

<Project Sdk="Microsoft.NET.Sdk">
... (more stuff) ...
  <ItemGroup>
    <ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" PrivateAssets="All" />
  </ItemGroup>
</Project>

and does not contain a reference to the DAL-project.