blog icon indicating copy to clipboard operation
blog copied to clipboard

Using dependency injection in multiple .NET Core projects

Open utterances-bot opened this issue 6 years ago • 3 comments

Using dependency injection in multiple .NET Core projects

https://asp.net-hacker.rocks/2017/03/06/using-dependency-injection-in-multiple-projects.html

utterances-bot avatar May 28 '19 12:05 utterances-bot

This is a neat approach - just what I needed to avoid having to add logical project references to indirect dependencies. :)

hannesRSA avatar May 28 '19 12:05 hannesRSA

How would this be done if one of the projects was a class library that does not have a program.cs or StartUp.cs but still need to have the db and setting json injected into some of the library classes?

KCRotaryUSA avatar Oct 01 '21 20:10 KCRotaryUSA

Hi @KCRotaryUSA This is exactly what I tried to explain here. At least you would have one single project in your solution that has a program.cs or a startup.cs. A project that uses your libraries. This project will set up the DI and arrange/compose the dependencies. This will also set up the classes of the class libraries that is depending on a db connection or a settings class that needs to be injected.

JuergenGutsch avatar Oct 19 '21 11:10 JuergenGutsch