Preventing .NET Core Nested Project References

前端 未结 2 1601
天涯浪人
天涯浪人 2020-12-20 20:52

Given the situation that I have a .NET Core 2.0 Application I also have a Web assembly, a Business assembly, and a DataAccess assembly.

I don\'t want the Web assembl

相关标签:
2条回答
  • 2020-12-20 21:07

    In order to prevent your DataAccess layer to be visible from a web layer, you should put PrivateAssets element inside a .csproj file of your business layer. Like in a code below.

    <ItemGroup>
     <ProjectReference Include="..\GiveAway.Data\GiveAway.Data.csproj">
       <PrivateAssets>all</PrivateAssets>
     </ProjectReference>
    </ItemGroup> 
    

    Here you can read more information about PrivateAssets element: https://docs.microsoft.com/en-us/dotnet/core/tools/csproj

    0 讨论(0)
  • 2020-12-20 21:14

    This is why you use interfaces, not concrete objects for injection. You shouldn't be leaking references to DBContext outside of your DataAccess assembly. This means you have too much coupling to the underlying database in the higher layers.

    0 讨论(0)
提交回复
热议问题