4

I have created Business and DataAccess Layer for my web project using dotnet core. I have added Data access reference in Business layer and referenced the business layer in UI (web project) layer.

I seen, I am able to access my Data access layer from my UI (web) project. I am really wondering, It can lead to violation of any application design.

Appreciate help, if anybody come across this and how to restrict access to data access layer from UI.

enter image description here

H H
  • 263,252
  • 30
  • 330
  • 514
Nizam Deen
  • 241
  • 2
  • 7
  • The simple solution is: Just don't do that. Just rely on Dependency Injection, I don't see you doing that yet. – H H Aug 08 '17 at 18:10
  • Answers from MVC team - https://github.com/aspnet/Mvc/issues/6635 – Nizam Deen Sep 05 '17 at 15:04
  • Same issue https://stackoverflow.com/questions/46160274/project-references-in-net-core-different-from-previous-net-versions i prefer to have it separate as well to avoid mistakes but it seems that is not longer how things work now. – Shikyo Feb 21 '18 at 02:08

1 Answers1

1

Yes, an indirect dependency is a dependency too.

And your toplevel (MVC) project has to reference everything, direct or indirect, in order to get all modules loaded. And to set up the dependency injection.

You can get better separation by introducing an interfaces layer in a separate project. For example IBusinessClass and IDataAccessClass.

That works for everything but the main project so if you want this particular separation from your example, move your Controllers to a separate project and depend that on the IBusiness interfaces only. Though I'm not sure how that works with MVC's conventions.

H H
  • 263,252
  • 30
  • 330
  • 514
  • To register the dependency, we need corresponding concrete classes to be accessible (should be public). Even though we says we are resolving through dependency, there are chances where i can create direct dependency with concrete classes. – Nizam Deen Aug 08 '17 at 18:34
  • Yes, that's what I meant with "to set up the dependency injection". You could avoid even that when you can find/create something similar to MEF for .Core. But I wouldn't bother. – H H Aug 08 '17 at 19:14