Anyname Donotcare
Anyname Donotcare

Reputation: 11423

How to limit the accessibility among different projects in .net core?

If I have for example three projects like this:

  1. WebApi(asp.net web core)
  2. Shared.Infrastructure(Contains Generic repo)
  3. DAL(Use EF Core)

The second project has a reference of the third project. and the first project(the api) has a reference of the second project.

What I had observed is:

All things in the third project is accessible in the first project (api) including the db context and the EF core !


I want the DAL to be not accessible expect from the second project. I don't want this transferable dependency between the first and the third project because now any one in the API can skip repo in the second project and use the third project (DAL) directly!

Upvotes: 0

Views: 99

Answers (1)

scharnyw
scharnyw

Reputation: 2686

One way to do that is to edit Shared.Infrastructure.csproj so that the DAL project is set as a PrivateAsset:

<ProjectReference Include="path-to-DAL.csproj">
  <PrivateAssets>all</PrivateAssets>
</ProjectReference>

See the reference on PrivateAssets here.

Upvotes: 1

Related Questions