Hi, I am about to add Dagger2 to a build, so I can...
# getting-started
r
Hi, I am about to add Dagger2 to a build, so I can put it on my CV/Resume. I don't "get" dependancy injection from what I have read online. Someone please "sell" me the idea to become a better developer with more skills.
🧌 3
d
Ok, say your App needs to send out notifications for various things. You write a
NotificationSender
which the components of your app can use to send notifications when needed. Every component of your App creates this
NotificationSender
so it can send notifications. You write a
EmailNotificationSender
which sends notifications via email and use that all over your code. Now, 2 weeks later your boss asks you to send notifications via SMS instead, because he wants to receive them on the go (whatever, stupid example). Now you have to change your whole app because you used
EmailNotificationSender
everywhere. If you use any kind of separation of concerns (dependency injection is just helping you achieve that) you only have to change this in one place:
val notificationSender = EmailNotificationSender()
becomes
val notificationSender = SMSNotificationSender()
. But there are much better, longer and more detailed articles online 😉
r
Wow, long reply, hang on a sec...
okay, not entirely sold but I will keep reading.
d
What issues do you have with it?
r
I've seen at my last Kotlin job my boss was injecting contexts into general classes... I am just unfamiliar with it... It takes a long time for things to "gel" with me sometimes. I guess I will just read up on it and probably do things badly until it clicks.
d
Good luck!