Are project references in .NET Core different from previous versions of .NET?

A new web Api is currently being created using C # and dotnet Core. And I notice strange behavior when linking to other projects.

My solutions are pretty straight forward: DataAccess, BusinessLogic, WebApi

The WebApi project has a link to the BusinessLogic project and the BusinessLogic project has a link to the DataAccess project.

Now with previous versions of .NET, my WebApi project would not have any access to anything from the DataAccess project, but in my current setup, I can access anything from the DataAccess project in my WebApi project without referencing it.

Can anyone explain this behavior and maybe how to prevent it?

0


source to share


1 answer


This is how you can get all the AspNetCore packages with just a link to Microsoft.AspNetCore.All.

The Microsoft docs detail Metapackaging .

Also note that since your application's composition root is WebAPI, you want it to see the types from DataAccess so that you can register them with the container.

One way to do this is to have an abstraction for persistence on your BusinessLogic as well. And invert the link (high level module should not depend on low level module) BusinessLogic and DataAccess.

Something like:

BusinessLogic:



  • User.cs
  • IUserRepository.cs

DataAccess:

  • UserRepository: IUserRepository

Now the WebAPI project can reference DataAccess and BusinessLogic and register with the container:

Register<IUserRepository, UserRepository>();

      

You can go ahead and have DataAccess.Abstractions for interfaces only, but that will depend on your project and how far you want to go.

+1


source







All Articles