C#C
C#3y ago
77 replies
REAL STUNNA

❔ Question about setting up dependency injection (console app with no async stuff)

So I've been trying to set up a dependency injection in my program for the first time to no avail. From what I've learned, a dependency injection allows you to use methods from another class without having to explicitly instantiate a new instance of the class which allows for loosely coupled code and less dependencies.

I was told I should be injecting my DBContext instead of calling a new context every time I do a database action. I think the way I have been approaching this fix is wrong in that I'm creating an interface for my Helpers class when in reality I should be making an interface for my PhoneBookContext class. Am I on the right track? Any feedback is appreciated.

Pasted code:
https://paste.mod.gg/hhwsmajvkxnq/2
A tool for sharing your source code with the world!
Was this page helpful?