简体   繁体   中英

Visual Studio Multi Project Solution Issue

I have this solution in VS 2017 which has multiple projects:

  • Example.DomainModels
  • Example.DataAccess
  • Example.Infrastructure
  • Example.Web

So well, my Web project references Infrastructure and the Infrastructure project references DataAccess as well as DomainModels projects. The solution is working fine.

However, if inside my Web project, if I try to access any of the entities from the DomainModels , I can easily access that without any errors, even though Web project doesn't have any reference to the DomainModels .

Can you please help me understand how this referencing of the project works? Is it because the web project has indirect reference to the DomainModels ( Web -> Infrastructure -> DomainModels )?

Thanks.

Please investigate the Onion architecture: https://social.technet.microsoft.com/wiki/contents/articles/36655.onion-architecture-in-asp-net-core-mvc.aspx

The Domain Model should not reference anything. In order to achieve this; you should investigate dependancy inversion. I asked a question recently about dependancy inversion here: Execute code in a class library when you do not have a reference to that class library

If you want to divorce the domain layer from the web then you could introduce a service layer.

Indeed , as per your comments web will have reference to all other projects

When you compile , The Infrastructure will be having references dataaccess and domain model namespaces attached to it hence you are able to access the types or namespaces present in dataaccess and domain models from web since you are refering Infrastructure from web .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM