-1

I am working with ASP.NET core right now and have configured dependencies with service collection in startup class. I have registered both business and data layer dependencies.

so for business layer dependency, I used:

services.AddScoped<ICountryService, CountryService>();

and for business layer dependency, I used:

services.AddScoped<ICountryRepository, CountryRepository>();

While working with this a question/confusion came across my mind that my web project will have reference to both business and data layer assemblies.

Is it a good idea that Presentation layer knows about or have a reference of data layer? Or Am I doing wrong something !!

curious
  • 1,504
  • 5
  • 18
  • 32
vibs
  • 115
  • 2
  • 14
  • How else will the UI know where to get the data. The important thing is the details of the implementation are hidden within its own respective layers. – Jasen Aug 10 '17 at 04:07
  • "The important thing is the details of the implementation are hidden within its own respective layers." That actually resolves my confusion. :) Thank you for your quick response. – vibs Aug 10 '17 at 04:22
  • [This answer to Ioc/DI - Why do I have to reference all layers/assemblies in entry application?](https://stackoverflow.com/a/9503612) sums it up well. – NightOwl888 Aug 10 '17 at 04:50

1 Answers1

0

You do the DI registration in the application root, in this case it's the web app startup. The registration module will often need to have references to all of your layers in order to wire everything up.

The data layer often is abstracted by some other layer (services) so that the rest of the web app never knows the details.

Jasen
  • 14,030
  • 3
  • 51
  • 68