0

I created a project in MVC 6 and I am using default framework of .net core for dependency injection. I have N layer architecture so to resolve the dependency I have to add references of all layer (e.g. Data layer) in UI layer because in startup.cs I am resolving the dependency which is a kind of violation.

So, can anyone share the idea- how to achieve this without adding the references of all layers to UI layer.

Current code-

services.AddTransient<ISusheelService, SusheelService>();

Thank you! Susheel rawat

Susheel Rawat
  • 85
  • 2
  • 9
  • 4
    `I have to add references of all layer (e.g. Data layer) in UI layer because in startup.cs I am resolving the dependency which is a kind of violation.` Actually, no, this is not a violation, but [desired DI behavior](https://stackoverflow.com/a/9503612/181087). A violation is tight coupling due to a complex network of dependent assemblies instead of making a flat structure that your composition root has total control over. And for that to happen, you need to reference all layers from the top layer. – NightOwl888 May 30 '17 at 18:12
  • you probably should move out of front layer all UI logic, composition root is another layer, which is aware of all others. – VMAtm May 30 '17 at 20:13
  • I wouldn't count the startup's ConfigureServices() to "UI layer code" but rather (hosting) infrastructure. There's also `IStartupFilter` to split this into multiple classes if necessary. – Martin Ullrich May 30 '17 at 21:15

0 Answers0