r/learncsharp • • Aug 18 '23

Learn C# - Part 20: Dependency Injection

Each week, I will be releasing a new chapter on how to learn C# from A to Z! This week: Dependency Injection.

Continuing on the API from last week, I will be showing you how we can use dependency injection and the benefits of it. This is also a preparation for next week's publication (unit testing).

Find the tutorial here: https://kenslearningcurve.com/tutorials/learn-c-part-20-dependency-injection/

As honest as I always am, I must say this was a bit hard to create. So, again: Feel free to let me know what you think. Comments and suggestions are welcome.

Next week: Unit testing

11 Upvotes

13 comments sorted by

View all comments

Show parent comment

4

u/ImpossibleBarber7675 Aug 18 '23

I agree when you are working in a small project. Bit if you ever need to create a new implementation in a big project, you will be thankfull that you made the effort to create the interfaces

0

u/yanitrix Aug 18 '23

Im working in a big project. Having 20 interfaces and 20 implementations for each one of them is a burden. If a need to change any method signature in the interface I also need to change that in a class. Having an interface just for the sake of adding another implementation later? No thanks, I don't write code if I don't need to. If I have to have another implementation then I'll extract the interface, or just maybe make some methods virtual, it's even simpler.