I know this question is frequently asked, but still It's not enough I will explain 'why', in my question.
I am trying to understand why DI is good, and when to use it, but I can't find good, clear and useful explanations and examples.
I found good question in comments and didn't get an answer.
DI makes the architecture vastly more complicated. And yet, as I see it, the use is pretty limited. The examples are certainly always the same: interchangeable loggers, interchangeable model / data access. Sometimes interchangeable view. But that’s it. Do these few cases really justify a vastly more complex software architecture?
As I see only answer on this question is unit testing, you can't or it's hard to test something when you are instantiating an object in it.
Other use-case I can understand also is loose coupling, but still your code is not fully decoupled when you are using DI, because your code is still depend on the interface you are using to inject different classes, because If that interface changes I have to change code where I am using that interface.
Aucun commentaire:
Enregistrer un commentaire