0

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?

mannok
  • 1,712
  • 1
  • 20
  • 30
  • See [Ioc/DI - Why do I have to reference all layers/assemblies in application's entry point?](https://stackoverflow.com/a/9503612). – NightOwl888 Jun 03 '20 at 15:36

1 Answers1

2

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.

MatteKarla
  • 2,707
  • 1
  • 20
  • 29
  • Yes, I remember this is the behavior in .NET Framework... I don't know why I can reference `DAL` from `Presentation Layer` in .NET Core. I am sure that I do not get `Presentation Project` refer to `DAL` – mannok Jun 03 '20 at 15:06
  • If you try to instantiate a class from DAL in Presentation Layer, then it won't compile if you try (and you have your project references correct). But I believe Visual Studio, and Rider etc. have "Quick Fixes" for what they believe is "the problem" so that you easily can add a reference to the DAL-project. – MatteKarla Jun 03 '20 at 15:24
  • seems the reason has been stated at https://stackoverflow.com/questions/46709000/disable-transitive-project-reference-in-net-standard-2, but still thanks for your help! – mannok Jun 03 '20 at 16:40