I've read the reasons why to use (not to use) DI (see reasons below), and have a few questions.
Dependency injection is effective in these situations:
- You need to inject configuration data into one or more components.
- You need to inject the same dependency into multiple components.
- You need to inject different implementations of the same dependency.
- You need to inject the same implementation in different configurations.
- You need some of the services provided by the container.
Dependency injection is not effective if:
- You will never need a different implementation.
- You will never need a different configuration.
Questions:
I afraid that don't understand all of them, so I hope you'll correct me if I'm wrong.
- Don't understand. Is that about .properties files or I can apply the same xml configuration to multiple beans?
- It's clear for me.
- It's clear for me.
- Don't understand. Example please.
- It's clear for me.
P.S. And how often there are situations when you never need different implementations/configurations as pointed above?