Purpose of Dependency Injection
In this example what's the benefit of DI here. I can just create instances of
I asked AI then it just mentioned:
EmailService and MessagingService class and call the SendMessage method on them without having to create an extra instance of the NotificationService class.I asked AI then it just mentioned:
- some theoretical information about how DI has loose coupling and all but couldn't prove any benefit in the code.
- how I can independently test the
NotificationServicebut I can just independently testMessagingService&EmailService. - how adding features to the
MessagingService&EmailServicecan cause problems but couldn't show me how it can cause problems in the code.