r/learnprogramming • u/Bofact • Oct 29 '26
Tutorial Dependency Injection confusing example
I am learning about Dependency Injection from the below link Dependency Injection in ASP comma NET MVC Tutorial | ASSIST Software, but in the first example is writing a prototype, in the second it creates "a separate class that has the responsibility of working with the database", but no class is created. He only implements the function from the example 1.
Am I missing something?
Edit: I initially put a link to the tutorial in question, but Reddit removed my post. So this is why this post doesn't have a link.
11
Upvotes
View all comments
2
u/Upstairs-Project2756 Oct 30 '26
you are not missing anything, the tutorial is just being lazy. The concrete database class likely already exists in their full codebase but wasn't shown to save space. You don't need a new separate class if you already have one working; you just change how the controller gets it. Replace `new DatabaseClass()` with `public Controller(IDatabase _db) { _db = ... }`. That is the actual DI step they skipped writing out